//权限管理-所有分组
App.models.add(new App.Model({
    name: 'operationGroups',
    url: 'admin/access/operationGroup/all'
}));
//销售主管
App.models.add(new App.Model({
    name: 'seller-managers',
    url: '/admin/access/user/sellerManagers'
}));
//货柜管理-全部供应商
App.models.add(new App.Model({
    name: 'factories-all',
    url: '/admin/cabinet/factory/all'
}));
//货柜管理-全部型号
App.models.add(new App.Model({
    name: 'type-all',
    url: '/admin/cabinet/type/all'
}));
//货柜管理-全部货柜
App.models.add(new App.Model({
    name: 'cabinets-all',
    url: '/admin/cabinet/cabinet/all'
}));
//店面管理-全部店面
App.models.add(new App.Model({
    name: 'storefront-all',
    url: '/admin/storefront/storefront/all'
}));
//店面管理-全部店面柜子里的格子排期
App.models.add(new App.Model({
    name: 'schedule-all',
    url: '/admin/storefront/schedule/all'
}));
//企业管理-全部企业
App.models.add(new App.Model({
    name: 'enterprise-all',
    url: '/admin/enterprise/enterprise/all'
}));
//供应商管理-全部供应商
App.models.add(new App.Model({
    name: 'supplier-all',
    url: '/admin/supplier/supplier/all'
}));
//商品管理-全部商品
App.models.add(new App.Model({
    name: 'goods-all',
    url: '/admin/goods/goods/all'
}));
//品牌管理-全部品牌
App.models.add(new App.Model({
    name: 'brand-all',
    url: '/admin/goods/brand/all'
}));
//商品管理-所以商品分类
App.models.add(new App.Model({
    name: 'goodstypes',
    url: '/admin/goods/goodstype/all'
}));
//商品管理-全部极秒排期
App.models.add(new App.Model({
    name: 'jmschedule-all',
    url: '/admin/goods/jmschedule/all'
}));
//商品管理-主题排期
App.models.add(new App.Model({
    name: 'jmtheme-all',
    url: '/admin/goods/jmtheme/all'
}));
//商品管理-分区排期
App.models.add(new App.Model({
    name: 'jmpartition-all',
    url: '/admin/goods/jmpartition/all'
}));
//物流管理-全部物流
App.models.add(new App.Model({
    name: 'logistics-all',
    url: '/admin/logistics/logistics/all'
}));
//物流管理-全部快递
App.models.add(new App.Model({
    name: 'delivers-all',
    url: '/admin/logistics/delivers/all'
}));
//用户管理-全部用户
App.models.add(new App.Model({
    name: 'user-all',
    url: '/admin/user/user/all'
}));
//订单管理-全部订单
App.models.add(new App.Model({
    name: 'orders-all',
    url: '/admin/orders/orders/all'
}));
//财务管理-全部定价
App.models.add(new App.Model({
    name: 'prices-all',
    url: '/admin/finance/price/all'
}));
//财务管理-全部发票
App.models.add(new App.Model({
    name: 'invoice-all',
    url: '/admin/finance/invoice/all'
}));
//卡劵管理-全部卡劵
App.models.add(new App.Model({
    name: 'card-all',
    url: '/admin/card/card/all'
}));
//数据统计-全部体验记录
App.models.add(new App.Model({
    name: 'experience-all',
    url: '/admin/experience/experience/all'
}));
//系统配置-操作管理-批量添加组件
App.util.ns('Admin.Access.Operation');
Admin.Access.Operation.MultiAdd = function(dataTable){
    var win = new App.Win({name: 'multi_add'});
    //列表
    var form = new App.Form({
        items: [
            {type: 'select', name: 'group_id', title: '所属分组', items: App.models.get('operationGroups'), item_key: 'group_id', item_name: 'name'},
            {type: 'textarea', name: 'items', title: '路由片段', 
                rule: {
                    type: 'str',
                    range: [1, 1000]
                }
            }
        ]
    });
    form.formItems['items'].frame.css({height: '300px'});
    form.formItems['items'].frame.find('.form-control').css({height: '100%'});
    win.form = form;
    win.setContent(form.frame);
    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">保存</a>');
        saveBtn.click(function(){
            var groupId = win.form.formItems['group_id'].value();
            var itemsStr = win.form.formItems['items'].value();
            if(groupId.length < 1 || itemsStr.length < 1){
                App.util.hint.toast({
                    type: 'error',
                    text: '格式不正确'
                });
                return;
            }
            var itemsRaw = itemsStr.split("\n");
            var items = [];
            var namespace = 'Admin';
            for(var i in itemsRaw){
                var itemStr = itemsRaw[i];
                //匹配命名空间
                if(itemStr.indexOf('Route::group') > -1){
                    var namespaceMatch = itemStr.match(/.*?\'namespace\'.*?\'(.*?)\'/);
                    if(namespaceMatch){
                        namespace += '\\'+namespaceMatch[1];
                    }
                    continue;
                }
                var itemMatch = itemStr.match(/.*?::(.*?)\(.*,.*['"](.*?)['"].*?\/\/(.*)/);
                if(itemMatch && itemMatch.length === 4){
                    var type = itemMatch[1];
                    var code = itemMatch[2];
                    var name = itemMatch[3];
                    if(code.length < 1 || name.length < 1){
                        App.util.hint.toast({
                            type: 'error',
                            text: '路由格式有误1'
                        });
                        return ;
                    }
                    var item = {
                        code: namespace ? namespace+'\\'+code : code,
                        name: name,
                        data_source: '',
                        data_id: 'id',
                        data_name: 'name'
                    };
                    if(type === 'get'){
                        items.push(item);
                        continue;
                    }
                    var method = code.split('@')[1];
                    if(method === 'create'){
                        item['data_source'] = '3';
                    }else if(method === 'update'){
                        item['data_source'] = '4';
                    }else if(method === 'delete'){
                        item['data_source'] = '6';
                    }else if(method === 'multiDelete'){
                        item['data_source'] = '6';
                    }else if(method === 'sort'){
                        item['data_source'] = '1';
                    }else{
                        item['data_source'] = '5';
                    }
                    items.push(item);
                }
            }
            if(items.length < 1){
                App.util.hint.toast({
                    type: 'error',
                    text: '未匹配到'
                });
                return ;
            }
            dataTable.postData({
                url: 'multiAdd',
                alert: '保存成功！',
                reload: true,
                data: {
                    group_id: groupId,
                    items: JSON.stringify(items)
                },
                after: function(){
                    win.hide();
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};
//系统配置-操作管理-配置文件
App.util.ns('Admin.Access.Operation');
Admin.Access.Operation.Conf = {
    columns: [
        {name: '操作编码', value: 'code'},
        {name: '操作名称', value: 'name', width: '200px', style: 'text-align: left;'},
        {name: '所属分组', width: '200px', value: function(item){
            return item.group ? item.group.name : '';
        }, style: 'text-align: left;'},
        {name: '数据来源', width: '100px', value: function(item){
            var logConfig = item.log_config ? JSON.parse(item.log_config) : {};
            switch (logConfig.data_source+'') {
                case '0':
                    return '自定义';
                case '1':
                    return '单条输入';
                case '2':
                    return '批量输入';
                case '3':
                    return '创建模型';
                case '4':
                    return '编辑模型';
                case '5':
                    return '修改模型';
                case '6':
                    return '删除模型';
                default: 
                    return '';
            };
        }},
        {name: '数据ID', width: '80px', value: function(item){
            var logConfig = item.log_config ? JSON.parse(item.log_config) : {};
            return logConfig.data_id || '';
        }},
        {name: '数据名称', width: '80px', value: function(item){
            var logConfig = item.log_config ? JSON.parse(item.log_config) : {};
            return logConfig.data_name || '';
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'select', title: '所属分组', name: 'group_id', width: '250px',
            items: App.models.get('operationGroups'),
            item_key: 'group_id', 
            item_name: 'name'
        },
        {type: 'input', name: 'name', title: '操作名称', rule: {
            type: 'str',
            range: [1, 250]
        }},
        {type: 'input', name: 'code', title: '操作编码', rule: {
            type: 'str',
            range: [1, 250]
        }},
        {type: 'hidden', name: 'log_config', title: '操作日志配置', onChange: function(self){
            var valueRaw = self.value();
            var value = valueRaw ? JSON.parse(self.value()) : {data_source: '', data_id: '', data_name: ''};
            self.form.formItems['data_source'].change(value.data_source || '');
            self.form.formItems['data_id'].change(value.data_id || '');
            self.form.formItems['data_name'].change(value.data_name || '');
        }},
        {type: 'select', name: 'data_source', title: '数据来源', items: [
            ['0', '自定义'],
            ['1', '单条输入'],
            ['2', '批量输入'],
            ['3', '创建模型'],
            ['4', '编辑模型'],
            ['5', '修改模型'],
            ['6', '删除模型']
        ]},
        [
            {type: 'input', name: 'data_id', title: '数据ID'},
            {type: 'input', name: 'data_name', title: '数据名称'}
        ]
    ]
};
//系统配置-操作管理
App.pages.add((function(){
    var NS = Admin.Access.Operation;
    var page = new App.Page({
        name: 'access/operation/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-folder"></i>',
            content: '系统配置'
        }, {
            content: '操作管理'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/access/operation',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'select', title: '所属分组', name: 'group_id', width: '250px',
                    items: App.models.get('operationGroups'),
                    item_key: 'group_id', 
                    item_name: 'name'
                }
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.access.operation.create'},
                {type: 'globe', permission: 'op:admin.access.operation.multiAdd', name: '批量添加', operation: function(dataTable){
                    var win = dataTable.wins.get('multiAdd');
                    win.setTitle('批量添加');
                    win.form.reset().add();
                    win.show();
                }},
                {parent: 'view', permission: 'op:admin.access.operation.detail'},
                {parent: 'edit', permission: 'op:admin.access.operation.update'},
                {parent: 'drop', permission: 'op:admin.access.operation.delete'},
                {parent: 'multiDrop', permission: 'op:admin.access.operation.multiDelete'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.MultiAdd(dataTable), 'multiAdd');
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//系统配置-操作分组-表单-数据源
App.util.ns('Admin.Access.OperationGroup.Form');
Admin.Access.OperationGroup.Form.DataSource = function(config){
    this.config = config;
    this.name = this.config.name;
    this.form = null;
    this.frame = null;
    this.inputFrame = null;
    this.viewFrame = null;
    //初始化
    this.init();
};
Admin.Access.OperationGroup.Form.DataSource.prototype = {
    constructor: Admin.Access.OperationGroup.Form.DataSource,
    init: function(){
        this.frame = $([
            '<div class="input-container">',
            '   <div class="input-group">',
            '       <input type="text" class="form-control" name="data_source_source" placeholder="class@method:params">',
            '       <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            '       <input type="text" class="form-control" name="data_source_key" placeholder="key">',
            '       <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            '       <input type="text" class="form-control" name="data_source_name" placeholder="name">',
            '   </div>',
            '   <span class="form-static" style="display: none;"></span>',
            '</div>'
        ].join(''));
        this.inputFrame = this.frame.find('.input-group');
        this.viewFrame = this.frame.find('.form-static');
        return this;
    },
    setForm: function(form){
        this.form = form;
    },
    change: function (val) {//改变
        var dataSource = JSON.parse(val) || {};
        this.frame.find('input[name="data_source_source"]').val(dataSource.source || '');
        this.frame.find('input[name="data_source_key"]').val(dataSource.key || '');
        this.frame.find('input[name="data_source_name"]').val(dataSource.name || '');
        return this;
    },
    view: function () {//查看
        this.inputFrame.hide();
        this.viewFrame.show();
        return this;
    },
    flushView: function () {
        var value = JSON.parse(this.value());
        this.viewFrame.text(value.source + ' -- ' + value.key + ' -- ' + value.name).show();
    },
    reset: function () {
        this.viewFrame.hide();
        this.frame.find('input[name="data_source_source"]').val('');
        this.frame.find('input[name="data_source_key"]').val('');
        this.frame.find('input[name="data_source_name"]').val('');
        this.frame.show();
        return this;
    },
    edit: function () {
        this.viewFrame.hide();
        this.inputFrame.show();
        return this;
    },
    value: function () {
        var self = this;
        return JSON.stringify({
            source: self.frame.find('input[name="data_source_source"]').val(),
            key: self.frame.find('input[name="data_source_key"]').val(),
            name: self.frame.find('input[name="data_source_name"]').val()
        });
    },
    enable: function () {
        this.frame.find('input').prop('disabled', false);
        return this;
    },
    disable: function () {
        this.frame.find('input').prop('disabled', true);
        return this;
    },
    validate: function () {
        if (this.form.formItems.type.value() + '' !== '2') {
            return true;
        }
        var rs = true;
        this.frame.find('input').each(function () {
            if ($(this).val().length < 1) {
                $(this).addClass('error').one('change', function () {
                    $(this).removeClass('error');
                });
                rs = false;
            }
        });
        return rs;
    },
    destroy: function(){
        this.frame.remove();
    }
};
//添加到库
App.Form.lib['admin-access-operationGroup-dataSource'] = Admin.Access.OperationGroup.Form.DataSource;
//系统配置-操作管理-配置文件
App.util.ns('Admin.Access.OperationGroup');
Admin.Access.OperationGroup.Conf = {
    columns: [
        {name: '名称', value: 'name', main: true},
        {name: '标识码', value: 'code', width: '250px', style: 'text-align: left;'},
        {name: '权限类型', width: '70px', value: function (item) {
            switch (item.type + '') {
                case '1':
                    return '操作';
                case '2':
                    return '数据';
                default:
                    return '';
            }
        }}
    ],
    form: [
        {type: 'hidden', name: 'group_id'},
        {type: 'input', name: 'name', title: '名称', rule: {
            type: 'str',
            range: [1, 250]
        }},
        {type: 'input', name: 'code', title: '标识码', rule: {
            type: 'str',
            range: [1, 250]
        }},
        {type: 'select', name: 'type', title: '权限类型', items: [
            ['1', '操作'],
            ['2', '数据']
        ], onChange: function (self) {
            if (self.value() + '' === '2') {
                self.form.items.data_source.show();
            } else {
                self.form.items.data_source.hide();
            }
        }},
        {type: 'admin-access-operationGroup-dataSource', name: 'data_source', title: '数据源'}
    ]
};
//系统配置-操作分组
App.pages.add((function(){
    var NS = Admin.Access.OperationGroup;
    var page = new App.Page({
        name: 'access/operationGroup/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-folder"></i>',
            content: '系统配置'
        }, {
            content: '操作分组'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/access/operationGroup',
            dataUrl: 'lists',
            table: {
                id: 'group_id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'select', title: '权限类型', name: 'type', width: '100px', items: [
                    [1, '操作'],
                    [2, '数据']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.access.operationGroup.create'},
                {parent: 'view', permission: 'op:admin.access.operationGroup.detail'},
                {parent: 'edit', permission: 'op:admin.access.operationGroup.update'},
                {parent: 'drop', permission: 'op:admin.access.operationGroup.delete'},
                {parent: 'multiDrop', permission: 'op:admin.access.operationGroup.multiDelete'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            afterChange: function(){
                App.models.get('operationGroups').refresh();
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//系统配置-角色管理-分配操作
App.util.ns('Admin.Access.Role');
Admin.Access.Role.OperationManage = function(dataTable){
    var printer = {
        frame: $([
            '<div class="tab-left">',
            '    <ul class="tab-bar">',
            '    </ul>',
            '    <div class="tab-content padding-sm">',
            '   </div>',
            '</div>'
        ].join('')),
        flush: function(data){
            var groups = this.getGroupedData(data);
            var barContainer = this.frame.find('.tab-bar');
            barContainer.children().each(function(){
                $(this).remove();
            });
            var contentContainer = this.frame.find('.tab-content');
            contentContainer.children().each(function(){
                $(this).remove();
            });
            for(var name in groups){
                this.getBar(name).appendTo(barContainer);
                this.getContent(groups[name]).appendTo(contentContainer);
            }
            barContainer.find('li').each(function(){
                $(this).click(function(){
                    barContainer.find('li').removeClass('active');
                    $(this).addClass('active');
                    contentContainer.find('.tab-pane').removeClass('active').removeClass('in');
                    var index = $(this).index();
                    contentContainer.find('.tab-pane').each(function(){
                        if($(this).index() === index){
                            $(this).addClass('active').addClass('in');
                        }
                    });
                });
            });
            barContainer.find('li').first().click();
        },
        getBar: function(name){
            return $([
                '<li>',
                                                '	<a href="javascript:void(0);">'+name+'</a>',
                                                '</li>'
            ].join(''));
        },
        getContent: function(groups){
            var container = this.getContentContainer();
            for(var i in groups){
                var item = this.getContentItem(groups[i]);
                item.appendTo(container);
            }
            //全选
            container.find('.select-all-btn').click(function(){
                var selected = $(this).prop('checked');
                container.find('.operation-group-ids').prop('checked', selected).change();
                container.find('.operation-ids').prop('checked', selected).change();
            });
            //全部展开
            container.find('.items-show-all-btn').click(function(){
                $(this).hide();
                container.find('.items-hide-all-btn').show();
                container.find('.items-show-btn').click();
            });
            //全部收起
            container.find('.items-hide-all-btn').click(function(){
                $(this).hide();
                container.find('.items-show-all-btn').show();
                container.find('.items-hide-btn').click();
            });
            return container;
        },
        getContentContainer: function(){
            return $([
                '<div class="tab-pane fade">',
                '   <div class="panel panel-default fadeInDown" style="margin-bottom:10px;">',
                '       <div class="panel-heading">',
                '           <div class="row">',
                '               <div class="col-sm-6">',
                '                   <label class="label-checkbox pull-left" style="margin:0;font-weight:normal;">',
                '                       <input type="checkbox" class="select-all-btn" style="margin:0;margin-right:5px;">',
                '                       <span class="custom-checkbox">全选</span>',
                '                   </label>',
                '               </div>',
                '               <div class="col-sm-6 text-right">',
                '                   <span class="items-show-all-btn" style="cursor: pointer;display:none;">全部展开 <i class="fa fa-chevron-down"></i></span>',
                '                   <span class="items-hide-all-btn" style="cursor: pointer;">全部收起 <i class="fa fa-chevron-up"></i></span>',
                '               </div>',
                '           </div>',
                '       </div>',
                '   </div>',
                '<div>'
            ].join(''));
        },
        getContentItem: function(group){
            var item = $([
                '<div class="panel panel-default fadeInDown" style="margin-bottom:10px;">',
                '	<div class="panel-heading">',
                '		<div class="row">',
                '			<div class="col-sm-6">',
                '				<label class="label-checkbox pull-left" style="margin:0;font-weight:normal;">',
                '					<input type="checkbox" class="group-select-all-btn operation-group-ids" value="'+group.group_id+'" style="margin:0;margin-right:2px;">',
                '                   <span class="custom-checkbox">'+group.name+'(<span class="selected-count">0</span>/<span class="total-count">0</span>)</span>',
                '				</label>',
                '			</div>',
                '			<div class="col-sm-6 text-right">',
                '				<span class="items-show-btn" style="cursor: pointer;display:none;"><i class="fa fa-chevron-down"></i></span>',
                '				<span class="items-hide-btn" style="cursor: pointer;"><i class="fa fa-chevron-up"></i></span>',
                '			</div>',
                '		</div>',
                '	</div>',
                '	<div class="panel-body"><div>',
                '<div>'
            ].join(''));
            //条目
            var colNum = group.type+'' === 2 ? 4 : 3;
            for(var i in group.operations){
                var operation = group.operations[i];
                var itemDiv = $([
                    '<div class="col-md-'+(12/colNum)+' no-padding">',
                    '   <label class="label-checkbox inline" style="margin:0;font-weight:normal;">',
                    '       <input type="checkbox" data-group-type="'+group.type+'" data-group-id="'+group.group_id+'" class="operation-ids" value="'+operation.key+'" style="margin:0;margin-right:2px;">',
                    '       <span class="custom-checkbox">'+operation.name+'</span></label>',
                    '   </label>',
                    '</div>'
                ].join(''));
                if(operation.selected){
                    itemDiv.find('input').prop('checked', true);
                }
                itemDiv.appendTo(item.find('.panel-body'));
            }
            //总数
            item.find('.total-count').text(item.find('.operation-ids').length);
            var getSelectedCount = function(){
                var selectedCount = 0;
                item.find('.operation-ids').each(function(){
                    if($(this).prop('checked')){
                        selectedCount++;
                    }
                });
                return selectedCount;
            };
            //已选
            item.find('.selected-count').text(getSelectedCount());
            //显示
            item.find('.items-show-btn').click(function(){
                $(this).hide();
                item.find('.items-hide-btn').show();
                item.find('.panel-body').show();
            });
            //隐藏
            item.find('.items-hide-btn').click(function(){
                $(this).hide();
                item.find('.items-show-btn').show();
                item.find('.panel-body').hide();
            });
            //监听多选框
            item.find('.operation-ids').change(function(){
                item.find('.selected-count').text(getSelectedCount());
            });
            //全选
            item.find('.group-select-all-btn').change(function(){
                var selected = $(this).prop('checked');
                item.find('.operation-ids').prop('checked', selected).change();
            });
            return item;
        },
        getGroupedData: function(data){
            var groups = {};
            for(var i in data){
                var item = data[i];
                var names = item.name.split('-');
                var name = names[0];
                if(!groups[name]){
                    groups[name] = [];
                }
                item.name = names.splice(1, names.length).join('-');
                groups[name].push(item);
            }
            return groups;
        },
        getData: function(){
            var selectedOperationsRaw = [];
            var selectedDataOperationsRaw = {};
            this.frame.find('.operation-ids:checked').each(function(){
                var groupType = $(this).attr('data-group-type');
                var groupId = $(this).attr('data-group-id');
                if(groupType+'' === '1'){
                    selectedOperationsRaw.push($(this).attr('value'));
                }else if(groupType+'' === '2'){
                    if(!selectedDataOperationsRaw['_'+groupId]){
                        selectedDataOperationsRaw['_'+groupId] = [$(this).attr('value')];
                    }else{
                        selectedDataOperationsRaw['_'+groupId].push($(this).attr('value'));
                    }
                }
            });
            var selectedOperationIds = selectedOperationsRaw.join(',');
            var selectedDataOperationsArr = [];
            for(var i in selectedDataOperationsRaw){
                selectedDataOperationsArr.push(i+':'+selectedDataOperationsRaw[i].join(','));
            }
            var selectedDataIds = selectedDataOperationsArr.join('|');
            return {
                operationIds : selectedOperationIds,
                dataIds : selectedDataIds
            };
        }
    };
    var win = new App.Win({name: 'operation_manage'});
    win.printer = printer;
    win.frame.find('.container').css({'padding-left': 0, 'padding-right':0});
    win.setTitle('分配操作');
    win.setContent(printer.frame);
    win.contentContainer.append('<input type="hidden" name="role_id">');
    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">保存</a>');
        saveBtn.click(function(){
            var data = printer.getData();
            dataTable.postData({
                url: 'changeOperations',
                alert: '保存成功！',
                reload: false,
                data: {
                    role_id: win.contentContainer.find('input[name="role_id"]').val(),
                    operation_ids: data.operationIds,
                    data_ids: data.dataIds
                },
                after: function(){
                    win.hide();
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};
//系统配置-角色管理
App.pages.add((function(){
    var NS = Admin.Access.Role;
    var page = new App.Page({
        name: 'access/role/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-folder"></i>',
            content: '系统配置'
        }, {
            content: '角色管理'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/access/role',
            dataUrl: 'lists',
            floatable: true,
            paginator: false,
            table: {
                id: 'role_id',
                main: 0,
                showId: false,
                withSelect: false,
                columns: [
                    {name: '角色名称', value: 'name'},
                    {name: '修改时间', value: 'updated_at', width: '150px'}
                ],
                getItems: function(data, table){
                    return {
                        rootKeyLength: 100,
                        lists: [],
                        frame: table.frame,
                        init: function(data){
                            this.rootKeyLength = 100;
                            this.lists = [];
                            this.printTr(data);
                            this.frame.removeClass('table-striped');
                            var tbody = this.frame.find('tbody');
                            tbody.find('tr').remove();
                            for(var i in this.lists){
                                var tr = this.lists[i];
                                var id = tr.attr('data-id');
                                var spaceCount = (id.length - this.rootKeyLength)/2;
                                var html = '<span>';
                                for(var i=0;i<spaceCount;i++){
                                    html += '&nbsp;&nbsp;&nbsp;&nbsp;';
                                }
                                html += '</span>';
                                $(html).prependTo(tr.find('td').first());
                                tr.appendTo(tbody);
                            }
                            tbody.find('.down').each(function(){
                                $(this).click(function(){
                                    var selfId = $(this).parent().parent().attr('data-id');
                                    tbody.find('tr').each(function(){
                                        if($(this).attr('data-id') === selfId){
                                            $(this).find('.down').hide();
                                            $(this).find('.up').show();
                                            return ;
                                        }
                                        if($(this).attr('data-parent-id') === selfId){
                                            $(this).show();
                                            if($(this).hasClass('has-sub')){
                                                $(this).find('.up').hide();
                                                $(this).find('.down').show();
                                            }
                                        }
                                    });
                                });
                            });
                            tbody.find('.up').each(function(){
                                $(this).click(function(){
                                    var selfId = $(this).parent().parent().attr('data-id');
                                    tbody.find('tr').each(function(){
                                        if($(this).attr('data-id') === selfId){
                                            $(this).find('.up').hide();
                                            $(this).find('.down').show();
                                            return ;
                                        }
                                        if($(this).attr('data-id').indexOf(selfId) === 0){
                                            $(this).hide();
                                        }
                                    });
                                });
                            });
                        },
                        printTr: function(data){
                            for(var key in data){
                                this.lists.push(this.getTr(data[key]));
                                if(data[key]['sub']){
                                    this.printTr(data[key]['sub']);
                                }
                            }
                        },
                        getTr: function(data){
                            var roleId = data['role_id_code']+'';
                            var parentId = data['parent_id_code'];
                            var updateTime = data['updated_at'];
                            if(roleId.length < this.rootKeyLength){
                                this.rootKeyLength = roleId.length;
                            }
                            var tr = $([
                                '<tr data-id="'+roleId+'" data-parent-id="'+parentId+'">',
                                '   <td style="text-align:left;">',
                                '       <a href="javascript:void(0)" title="展开" class="down" style="display:none;">',
                                '           <i class="fa fa-plus"></i>',
                                '       </a>',
                                '       <a href="javascript:void(0)" title="收起" class="up" style="display:none;">',
                                '           <i class="fa fa-minus"></i>',
                                '       </a>',
                                '       <a href="javascript:void(0)" class="none" style="display:none;">',
                                '           <i class="fa fa-ban"></i>',
                                '       </a>',
                                '       '+data['name'],
                                '   </td>',
                                '   <td style="text-align:center;">',
                                '       '+App.util.formator.dateTime(updateTime),
                                '   </td>',
                                '</tr>'
                            ].join(''));
                            if(data.sub_count > 0){
                                tr.addClass('has-sub');
                                tr.find('.up').show();
                            }else{
                                tr.find('.none').show();
                            }
                            tr.find('td').first().addClass('main');
                            tr.attr('data-data', JSON.stringify(data));
                            return tr;
                        }
                    }.init(data);
                }
            },
            menu: [
                {parent: 'add', permission: 'op:admin.access.role.create'},
                {parent: 'view', permission: 'op:admin.access.role.detail'},
                {parent: 'edit', permission: 'op:admin.access.role.update'},
                {parent: 'drop', permission: 'op:admin.access.role.delete', operation: function(dataTable, data){ 
                    App.util.hint.confirm({
                        text: '删除角色会将该角色及其所有子角色一起删除，你确定要删除吗？',
                        yes: function(){
                            var id = dataTable.config.table.id;
                            var postData = {};
                            postData[id] = data[id];
                            dataTable.postData({
                                url: 'delete',
                                data: postData,
                                alert: '删除成功！',
                                reload: true
                            });
                        }
                    });
                }},
                {type: 'inline', permission: 'op:admin.access.role.changeOperations', name: '分配操作', operation: function(dataTable, data){
                    var win = dataTable.wins.get('operationManage');
                    //填充内容
                    App.util.request.getData({
                        url: dataTable.url('getOperations'),
                        data: {role_id: data.role_id},
                        success: function(roles){
                            win.setTitle('分配操作 - '+data.name);
                            win.printer.flush(roles);
                            win.contentContainer.find('input[name="role_id"]').val(data.role_id);
                            win.show();
                        }
                    });
                }},
                {type: 'inline', permission: 'op:admin.access.role.create', name: '添加子角色', operation: function(dataTable, data){
                    dataTable.detail.add();
                    dataTable.detail.form.add().reset().change({parent_id: data.role_id});
                    dataTable.detail.win.setTitle('添加子角色 - '+data.name).show();
                }},
                {parent: 'oplog', permission: 'op:admin.access.role.getOpLogs'}
            ],
            detail: {
                form: {
                    items: [
                        {type: 'hidden', name: 'role_id'},
                        {type: 'hidden', name: 'parent_id'},
                        {type: 'input', name: 'name', title: '角色名称', rule: {
                            type: 'str',
                            range: [1, 250]
                        }},
                        {type: 'textarea', name: 'description', title: '角色简介', rule: {
                            type: 'str',
                            range: [0, 250]
                        }}
                    ]
                }
            }, 
            after: function(dataTable){
                //分配操作
                dataTable.wins.add(new NS.OperationManage(dataTable), 'operationManage');
            },
            afterChange: function(){
                //通知
                App.pages.get('access/role/index').dirty();
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//系统配置-账号管理-配置文件
App.util.ns('Admin.Access.User');
Admin.Access.User.Conf = {
    columns: [
        {name: '账号', value: 'username'},
        {name: '状态', width: '70px', value: function(item){
            switch (item.status+'') {
                case '0':
                    return '停用';
                case '1':
                    return '启用';
                default: 
                    return '';
            }
        }},
        {name: '昵称', value: 'nickname', width: '200px'},
        {name: '姓名', value: 'name', width: '100px'},
        {name: '手机号码', value: 'phone', width: '100px'},
        {name: '邮箱', value: 'email', width: '200px'}
    ],
    form: [
        {type: 'hidden', name: 'user_id'},
        {type: 'input', name: 'username', title: '用户名', rule: {
            type: 'str',
            range: [1, 100]
        }},
        {type: 'password', name: 'password', title: '密码', rule: {
            type: 'str',
            range: [1, 100]
        }},
        {type: 'password', name: 're_password', title: '确认密码', rule: {
            type: 'str',
            range: [1, 100]
        }},
        {type: 'input', name: 'nickname', title: '昵称', rule: {
            type: 'str',
            range: [1, 100]
        }},
        {type: 'img', name: 'icon', title: '头像', rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'textarea', name: 'introduction', title: '简介', rule: {
            type: 'str',
            range: [0, 250]
        }},
        {type: 'input', name: 'name', title: '姓名', rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'input', name: 'phone', title: '手机', rule: {
            type: 'phone',
            range: [0, 100]
        }},
        {type: 'input', name: 'email', title: '邮箱', rule: {
            type: 'email',
            range: [0, 100]
        }}
    ]
};
//系统配置-用户管理-重置密码
App.util.ns('Admin.Access.User');
Admin.Access.User.ResetPassword = function(dataTable){
    var win = new App.Win({name: 'reset_password', width: '350px'});
    //表单
    var form = new App.Form({items: [
        {type: 'password', name: 'password', title: '新密码', rule: {
            type: 'str',
            range: [1, 100]
        }},
        {type: 'password', name: 're_password', title: '确认密码', rule: {
            type: 'str',
            range: [1, 100]
        }},
        {type: 'hidden', name: 'user_id'}
    ]});
    form.fix(win.contentContainer);
    win.form = form;
    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">保存</a>');
        saveBtn.click(function(){
            dataTable.postData({
                url: 'resetPassword',
                alert: '保存成功！',
                reload: false,
                data: form.getData(),
                after: function(){
                    win.hide();
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};
//系统配置-用户管理-角色管理
App.util.ns('Admin.Access.User');
Admin.Access.User.RoleManage = function(dataTable){
    //无限极折叠
    var printer = {
        rootKeyLength: 100,
        lists: [],
        frame: $([
            '<table class="table table-hover no-margin data-table">',
            '   <thead>',
            '       <tr>',
            '           <th style="text-align:center;">角色</th>',
            '           <th width="80px" style="text-align:center;">选择</th>',
            '       </tr>',
            '   </thead>',
            '   <tbody>',
            '   </tbody>',
            '</table>'
        ].join('')),
        flush: function(data, selected){
            this.rootKeyLength = 100;
            this.lists = [];
            this.printTr(data);
            var tbody = this.frame.find('tbody');
            tbody.children().each(function(){
                $(this).remove();
            });
            tbody.append(this.getEmptyTr());
            for(var i in this.lists){
                var tr = this.lists[i];
                var id = tr.attr('data-id');
                var spaceCount = (id.length - this.rootKeyLength)/2;
                var html = '<span>';
                for(var i=0;i<spaceCount;i++){
                    html += '&nbsp;&nbsp;&nbsp;&nbsp;';
                }
                html += '</span>';
                $(html).prependTo(tr.find('td').first());
                tr.appendTo(tbody);
            }
            tbody.find('input[name="role_id"][value="'+selected+'"]').prop('checked', true);
            tbody.find('.down').each(function(){
                $(this).click(function(){
                    var selfId = $(this).parent().parent().attr('data-id');
                    tbody.find('tr').each(function(){
                        if($(this).attr('data-id') === selfId){
                            $(this).find('.down').hide();
                            $(this).find('.up').show();
                            return ;
                        }
                        if($(this).attr('data-parent-id') === selfId){
                            $(this).show();
                            if($(this).hasClass('has-sub')){
                                $(this).find('.up').hide();
                                $(this).find('.down').show();
                            }
                        }
                    });
                });
            });
            tbody.find('.up').each(function(){
                $(this).click(function(){
                    var selfId = $(this).parent().parent().attr('data-id');
                    tbody.find('tr').each(function(){
                        if($(this).attr('data-id') === selfId){
                            $(this).find('.up').hide();
                            $(this).find('.down').show();
                            return ;
                        }
                        if($(this).attr('data-id').indexOf(selfId) === 0){
                            $(this).hide();
                        }
                    });
                });
            });
        },
        getEmptyTr: function(){
            return $([
                '<tr data-id="" data-parent-id="">',
                '   <td style="text-align:left;">',
                '       无',						
                '   </td>',
                '   <td style="text-align:center;">',
                '       <label class="label-radio inline">',
                '           <input type="radio" name="role_id" value="0">',
                '           <span class="custom-radio"></span>',
                '       </label>',
                '   </td>',
                '</tr>'
            ].join(''));
        },
        printTr: function(data){
            for(var key in data){
                this.lists.push(this.getTr(data[key]));
                if(data[key]['sub']){
                    this.printTr(data[key]['sub']);
                }
            }
        },
        getTr: function(data){
            var roleId = data['role_id_code']+'';
            var parentId = data['parent_id_code'];
            if(roleId.length < this.rootKeyLength){
                this.rootKeyLength = roleId.length;
            }
            var tr = $([
                '<tr data-id="'+roleId+'" data-parent-id="'+parentId+'">',
                '   <td style="text-align:left;">',
                '       <a href="javascript:void(0)" title="展开" class="down" style="display:none;">',
                '           <i class="fa fa-plus"></i>',
                '       </a>',
                '       <a href="javascript:void(0)" title="收起" class="up" style="display:none;">',
                '           <i class="fa fa-minus"></i>',
                '       </a>',
                '       <a href="javascript:void(0)" class="none" style="display:none;">',
                '           <i class="fa fa-ban"></i>',
                '       </a>',
                '       '+data['name'],
                '   </td>',
                '   <td style="text-align:center;">',
                '       <label class="label-radio inline">',
                '           <input type="radio" name="role_id" value="'+data['role_id']+'">',
                '           <span class="custom-radio"></span>',
                '       </label>',
                '   </td>',
                '</tr>'
            ].join(''));
            if(data.sub_count > 0){
                tr.addClass('has-sub');
                tr.find('.up').show();
            }else{
                tr.find('.none').show();
            }
            return tr;
        }
    };
    var win = new App.Win({name: 'operation_manage'});
    win.printer = printer;
    win.setContent(win.printer.frame);
    win.contentContainer.append('<input type="hidden" name="user_id">');
    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">保存</a>');
        saveBtn.click(function(){
            dataTable.postData({
                url: 'changeRole',
                alert: '保存成功！',
                reload: false,
                data: {
                    user_id: win.contentContainer.find('input[name="user_id"]').val(),
                    role_id: (function(){
                        var role_id = 0;
                        win.contentContainer.find('input[name="role_id"]').each(function(){
                            if($(this).prop('checked')){
                                role_id = $(this).val();
                            }
                        });
                        return role_id;
                    })()
                },
                after: function(){
                    win.hide();
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};
//系统配置-用户管理
App.pages.add((function(){
    var NS = Admin.Access.User;
    var page = new App.Page({
        name: 'access/user/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-folder"></i>',
            content: '系统配置'
        }, {
            content: '用户管理'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/access/user',
            dataUrl: 'lists',
            table: {
                id: 'user_id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '用户状态', width: '100px', items: [
                    ['1', '开启'],
                    ['0', '关闭']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.access.user.create'},
                {parent: 'view', permission: 'op:admin.access.user.detail'},
                {parent: 'edit', permission: 'op:admin.access.user.update'},
                {type: 'inline', permission: 'op:admin.access.user.open', name: '开启', operation: {type: 'change', url: 'open'}, conditions: [['status', '0']]},
                {type: 'inline', permission: 'op:admin.access.user.close', name: '关闭', operation: {type: 'change', url: 'close'}, conditions: [['status', '1']]},
                {parent: 'drop', permission: 'op:admin.access.user.delete'},
                {type: 'inline', permission: 'op:admin.access.user.resetPassword', name: '重置密码', operation: function(dataTable, user){
                    var win = dataTable.wins.get('resetPassword');
                    win.form.change({password: '', re_password: '', user_id: user.user_id});
                    win.setTitle('重置密码 - '+user.nickname+'（'+user.username+'）');
                    win.show();
                }},
                {type: 'inline', permission: 'op:admin.access.user.changeRole', name: '角色管理', operation: function(dataTable, user){
                    var win = dataTable.wins.get('roleManage');
                    //填充内容
                    App.util.request.getData({
                        url: dataTable.url('getWithRole'),
                        data: {user_id: user.user_id},
                        success: function(data){
                            var selected = data.user.role_id === null ? 0 : data.user.role_id;
                            var roles = data.roles;
                            win.setTitle('角色管理 - '+user.nickname+'（'+user.username+'）');
                            win.contentContainer.find('input[name="user_id"]').val(user.user_id);
                            win.printer.flush(roles, selected);
                            win.show();
                        }
                    });
                }},
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.access.user.multiOpen', name: '开启', operation: {type: 'change', url: 'multiOpen', confirm: true}},
                    {type: 'multi', permission: 'op:admin.access.user.multiClose', name: '关闭', operation: {type: 'change', url: 'multiClose', confirm: true}}
                    ], permission: [
                        'op:admin.access.user.multiOpen',
                        'op:admin.access.user.multiClose'
                ]},
                {parent: 'multiDrop', permission: 'op:admin.access.user.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.access.user.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form),
                    add: 'all',
                    edit: 'except:password,re_password',
                    view: 'except:password,re_password'
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.ResetPassword(dataTable), 'resetPassword');
                dataTable.wins.add(new NS.RoleManage(dataTable), 'roleManage');
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//货柜管理-供应商列表-配置文件
App.util.ns('Admin.Cabinet.Factory');
Admin.Cabinet.Factory.Conf = {
    columns: [
        {name: '厂商名称', value: 'name'},
        {name: '联系人员', width: '120px',value: 'contact_name'},
        {name: '联系电话', width: '120px',value: 'contact_tel'},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '厂商名称', required: true, maxLength: 100, rule: {
            type: 'str',
            range: [1, 100]
        }},
        {type: 'input', name: 'contact_name', title: '联系人员', rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'input', name: 'contact_tel', title: '联系电话', rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'textarea', name: 'introduction', title: '简介', maxLength: 500, rule: {
            type: 'str',
            range: [0, 500]
        }}
    ]
};
//货柜管理-供应商列表
App.util.ns('Admin.Cabinet.Factory');
App.pages.add((function(){
    var NS = Admin.Cabinet.Factory;
    var page = new App.Page({
        name: 'cabinet/factory/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-window-restore"></i>',
            content: '货柜管理'
        }, {
            content: '厂家管理'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/cabinet/factory',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.cabinet.cabinetFactory.create'},
                {parent: 'view', permission: 'op:admin.cabinet.cabinetFactory.detail'},
                {parent: 'edit', permission: 'op:admin.cabinet.cabinetFactory.update'},
                {parent: 'drop', permission: 'op:admin.cabinet.cabinetFactory.delete'},
                {parent: 'multiDrop', permission: 'op:admin.cabinet.cabinetFactory.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.cabinet.cabinetFactory.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//货柜与商品-货柜型号-配置文件
App.util.ns('Admin.Cabinet.Type');
Admin.Cabinet.Type.Conf = {
    columns: [
        {name: '型号名', value: 'name'},
        {name: '格子数', width: '100px',value: 'cells'},
        {name: '规格', width: '120px',value: function(item){
              return item.rows + '行，' + item.cols+'列';  
        }},
        {name: '生产厂家', width: '200px', value: function(item){
            return item.factory ? item.factory.name : '';
        }},
        {name: '状态', width: '80px',value: function(item){
            switch (item.status+'') {
                case '0':
                    return '下线';
                case '1':
                    return '在线';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '型号名称', required: true, maxLength: 100, rule: {
            type: 'str',
            range: [1, 200]
        }},
        {type: 'chosen', name: 'factory_id', title: '生产厂家', required: true,
            items: App.models.get('factories-all'), 
            item_key: 'id', 
            item_name: 'name', 
            value_key: 'id',
            rule:{
                type: 'num',
                range: [1, 10]
            }
        },
        [
            {type: 'input', name: 'rows', title: '行数', required: true, 
                rule: {
                    type: 'str',
                    range: [1, 40]
                },
                onChange: function(self){
                    return ;
                    var rowsRaw = self.value();
                    var colsRaw = self.form.formItems['cols'].value();
                    var rows = rowsRaw ? parseInt(rowsRaw) : 0;
                    var cols = colsRaw ? parseInt(colsRaw) : 0;
                    self.form.formItems['cols'].change(rows*cols);
                }
            },
            {type: 'input', name: 'cols', title: '列数', required: true, 
                rule: {
                    type: 'int',
                    range: [1, 100]
                },
                onChange: function(self){
                    return ;
                    var rowsRaw = self.value();
                    var colsRaw = self.form.formItems['cols'].value();
                    var rows = rowsRaw ? parseInt(rowsRaw) : 0;
                    var cols = colsRaw ? parseInt(colsRaw) : 0;
                    self.form.formItems['cols'].change(rows*cols);
                }}   
        ],
        {type: 'input', name: 'cells', title: '格子总数', required: true, 
            rule: {
                type: 'int',
                range: [1, 100]
            }
        },
        {type: 'img', name: 'icon', title: '样图', rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'textarea', name: 'introduction', title: '简介', maxLength: 200,
            rule: {
            type: 'str',
            range: [0, 200]
        }}
    ]
};
//货柜管理-型号列表
App.util.ns('Admin.Cabinet.Type');
App.pages.add((function(){
    var NS = Admin.Cabinet.Type;
    var page = new App.Page({
        name: 'cabinet/type/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-window-restore"></i>',
            content: '货柜管理'
        }, {
            content: '型号管理'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/cabinet/type',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [0, '下线'],
                    [1, '在线']
                ]},
                {type: 'select', name: 'factory_id', title: '生产厂商', width: '120px',
                    items: App.models.get('factories-all'),
                    item_key: 'id',
                    item_name: 'name',
                    change:function (self) {
                        var cabinets = App.models.get('factories-all');
                        console.log('111');
                    }
                }
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.cabinet.cabinetType.create'},
                {parent: 'view', permission: 'op:admin.cabinet.cabinetType.detail'},
                {parent: 'edit', permission: 'op:admin.cabinet.cabinetType.update'},
                {parent: 'drop', permission: 'op:admin.cabinet.cabinetType.delete'},
                {type: 'inline', permission: 'op:admin.cabinet.cabinetType.online', name: '上线', operation: {type: 'change', url: 'online'}, conditions: [['status', '0']]},
                {type: 'inline', permission: 'op:admin.cabinet.cabinetType.offline', name: '下线', operation: {type: 'change', url: 'offline'}, conditions: [['status', '1']]},
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.cabinet.cabinetStore.multiOnline', name: '上线', operation: {type: 'change', url: 'multiOnline', confirm: true}},
                    {type: 'multi', permission: 'op:admin.cabinet.cabinetStore.multiOffline', name: '下线', operation: {type: 'change', url: 'multiOffline', confirm: true}}
                ], permission:[
                    'op:admin.cabinet.cabinetType.multiOnline',
                    'op:admin.cabinet.cabinetType.multiOffline'
                ]},
                {parent: 'multiDrop', permission: 'op:admin.cabinet.cabinetType.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.cabinet.cabinetType.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//货柜管理-货柜列表-配置文件
App.util.ns('Admin.Cabinet.Cabinet');
Admin.Cabinet.Cabinet.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '店面', width: '200px', value: function(item){
            return item.storefront ? item.storefront.name : '';
        }},
        {name: '型号', width: '150px', value: function(item){
            return item.type ? item.type.name : '';
        }},
        {name: '格子数', width: '100px', value: function(item){
            var link = $('<a href=""></a>')
            return item.type ? item.type.cells : '';
        }},
        {name: '地址编号', width: '120px',value: 'code'},
        {name: '是否交押金', width: '80px',value: function(item){
            switch (item.is_deposit+'') {
                case '0':
                    return '否';
                case '1':
                    return '是';
            }
        }},
        {name: '状态', width: '80px',value: function(item){
            switch (item.status+'') {
                case '0':
                    return '未部署';
                case '1':
                    return '已部署';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'chosen', name: 'storefront_id', title: '店铺',required: true,
            items: App.models.get('storefront-all'),
            item_key: 'id',
            item_name: 'name',
            value_key: 'id',
            rule:{
                type: 'num',
                range: [1, 10]
            }
        },
        {type: 'chosen', name: 'type_id', title: '型号', required: true,
            items: App.models.get('type-all'),
            item_key: 'id',
            item_name: 'name',
            value_key: 'id',
            rule:{
                type: 'num',
                range: [1, 10]
            }
        },
        {type: 'input', name: 'code', title: '地址编号', rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'textarea', name: 'introduction', title: '简介', maxLength: 200,
            rule: {
            type: 'str',
            range: [0, 200]
        }}
    ]
};
//货柜管理-货柜列表
App.util.ns('Admin.Cabinet.Cabinet');
App.pages.add((function(){
    var NS = Admin.Cabinet.Cabinet;
    var page = new App.Page({
        name: 'cabinet/cabinet/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-window-restore"></i>',
            content: '货柜管理'
        }, {
            content: '柜子管理'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/cabinet/cabinet',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'is_deposit', title: '是否交押金', width: '95px', items: [
                    [0, '否'],
                    [1, '是']
                ]},
                {type: 'select', name: 'status', title: '状态', width: '80px', items: [
                    [0, '未部署'],
                    [1, '已部署']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.cabinet.cabinet.create'},
                {parent: 'view', permission: 'op:admin.cabinet.cabinet.detail'},
                {parent: 'edit', permission: 'op:admin.cabinet.cabinet.update'},
                {type: 'inline', permission: 'gp:admin/cabinet/cell', name: '格子管理',
                    operation: function(dataTable, cabinet){
                        App.nav.open('cabinet/cell/index', {
                            cabinet_id: cabinet.id,
                            cabinet_name: cabinet.name
                        });
                    }
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinet.open',
                    name: '激活', operation: {type: 'change', url: 'open'},
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinet.close',
                    name: '禁用', operation: {type: 'change', url: 'close'},
                    conditions: [['status', '1']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinet.need',
                    name: '交押金', operation: {type: 'change', url: 'need'},
                    conditions: [['is_deposit', '0']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinet.notneed',
                    name: '不交押金', operation: {type: 'change', url: 'notneed'},
                    conditions: [['is_deposit', '1']]
                },
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.cabinet.cabinet.multiOpen', name: '激活', operation: {type: 'change', url: 'multiOpen', confirm: true}},
                    {type: 'multi', permission: 'op:admin.cabinet.cabinet.multiClose', name: '禁用', operation: {type: 'change', url: 'multiClose', confirm: true}}
                ], permission:[
                    'op:admin.cabinet.cabinet.multiOpen',
                    'op:admin.cabinet.cabinet.multiClose'
                ]},
                {parent: 'drop', permission: 'op:admin.cabinet.cabinet.delete'},
                {parent: 'multiDrop', permission: 'op:admin.cabinet.cabinet.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.cabinet.cabinet.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//货柜管理-格子列表-配置文件
App.util.ns('Admin.Cabinet.Cell');
Admin.Cabinet.Cell.Conf = {
    columns: [
        {name: '位置', value: function(item){
              return item.row + ' 行，' + item.col + ' 列';
        }},
        {name: 'rfid', width: '220px',value: 'rfid'},
        {name: '编号', width: '60px',value: 'code'},
        {name: '商品', width: '290px', value: function(item){
            return item.goods ? item.goods.name : '未分配';
        }},
        {name: '价格', width: '100px', value: function(item){
            return item.price ? item.price.name : '未选择';
        }},
        {name: '状态', width: '80px', value: function(item){
            switch (item.status+'') {
                case '0':
                    return '空闲';
                case '1':
                    return '使用中';
                case '2':
                    return '故障';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        [
            {type: 'static', name: 'row', title: '所属行', rule: {
                type: 'str',
                range: [0, 40]
            }},
            {type: 'static', name: 'col', title: '所属列', rule: {
                type: 'str',
                range: [0, 100]
            }}
        ],
        {type: 'input', name: 'rfid', title: 'rfid', rule: {
            type: 'str'
        }},
        {type: 'input', name: 'code', title: '编号', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'chosen', name: 'price_id', title: '价格', required: true,
            items: App.models.get('prices-all'), 
            item_key: 'id', 
            item_name: 'name', 
            value_key: 'id',
            rule: {
                type: 'num',
                range: [0, 10]
            }
        }
    ]
};
//货柜管理-格子列表
App.util.ns('Admin.Cabinet.Cell');
App.pages.add((function(){
    var NS = Admin.Cabinet.Cell;
    var page = new App.Page({
        name: 'cabinet/cell/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/cabinet/cell',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [0, '空闲'],
                    [1, '使用中'],
                    [2, '故障']
                ]}
            ],
            menu: [
                {parent: 'view', permission: 'op:admin.cabinet.cabinetCell.detail'},
                {parent: 'edit', permission: 'op:admin.cabinet.cabinetCell.update'},
                {type: 'inline', permission: 'op:admin.cabinet.cabinetCell.renting', name: '租用', 
                    operation: {type: 'change', url: 'renting'}, 
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinetCell.rented', name: '归还', 
                    operation: {type: 'change', url: 'rented'}, 
                    conditions: [['status', '1']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinetCell.repair', name: '报修', 
                    operation: {type: 'change', url: 'repair'}, 
                    conditions: [['status', '1']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinetCell.replace', name: '修复', 
                    operation: {type: 'change', url: 'replace'}, 
                    conditions: [['status', '2']]
                },
                {parent: 'drop', permission: 'op:admin.cabinet.cabinetCell.delete'},
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.cabinet.cabinetCell.multiRenting', name: '租用', operation: {type: 'change', url: 'multiRenting', confirm: true}},
                    {type: 'multi', permission: 'op:admin.cabinet.cabinetCell.multiRented', name: '归还', operation: {type: 'change', url: 'multiRented', confirm: true}},
                    {type: 'multi', permission: 'op:admin.cabinet.cabinetCell.multiRepair', name: '报修', operation: {type: 'change', url: 'multiRepair', confirm: true}},
                    {type: 'multi', permission: 'op:admin.cabinet.cabinetCell.multiReplace', name: '修复', operation: {type: 'change', url: 'multiReplace', confirm: true}}
                    ], permission:[
                        'op:admin.cabinet.cabinetCell.multiReplace',
                        'op:admin.cabinet.cabinetCell.multiRepair',
                        'op:admin.cabinet.cabinetCell.multiRenting',
                        'op:admin.cabinet.cabinetCell.multiRented'
                ]},
                {parent: 'oplog', permission: 'op:admin.cabinet.cabinetCell.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
    });
    //页面打开
    page.showStack.add('openPage', function(){
        if(this.params){
            var params = this.params;
            //设置面包屑导航
            this.setBreadcrumb([{
                icon: '<i class="fa fa-window-restore"></i>',
                content: '货柜与商品'
            }, {
                content: '货柜管理',
                action: function(){
                    App.nav.back();
                }
            }, {
                active: true,
                content: '格子管理 - ' + params['cabinet_name']
            }]);
            //设置参数
            for(var i in params){
                this.dataTable.param.set(i, params[i]);
            }
            if(this.dataTable.paginator){
                this.dataTable.paginator.currentPage = 1;
            }
            //加载数据
            this.dataTable.loadData();
        }
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//店面管理-店面列表-配置文件
App.util.ns('Admin.Storefront.Storefront');
Admin.Storefront.Storefront.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '地理位置', width: '300px',value: 'address'},
        {name: '状态', width: '80px',value: function(item){
            switch (item.status+'') {
                case '1':
                    return '上线';
                case '2':
                    return '下线';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'img', name: 'imgs', title: '图集',rule: {
            type: 'str',
            range: [0, 255]
        }},
        [
            {type: 'input', name: 'lng', title: '经度', required: true,
                rule: {
                    type: 'str',
                    range: [1, 40]
                },
                onChange: function(self){
                    return ;
                    var rowsRaw = self.value();
                    var colsRaw = self.form.formItems['lat'].value();
                    var rows = rowsRaw ? parseInt(rowsRaw) : 0;
                    var cols = colsRaw ? parseInt(colsRaw) : 0;
                    self.form.formItems['lat'].change(rows*cols);
                }
            },
            {type: 'input', name: 'lat', title: '纬度', required: true,
                rule: {
                    type: 'int',
                    range: [1, 100]
                },
                onChange: function(self){
                    return ;
                    var rowsRaw = self.value();
                    var colsRaw = self.form.formItems['lat'].value();
                    var rows = rowsRaw ? parseInt(rowsRaw) : 0;
                    var cols = colsRaw ? parseInt(colsRaw) : 0;
                    self.form.formItems['lat'].change(rows*cols);
                }}
        ],
        {type: 'input', name: 'address', title: '地理位置', rule: {
            type: 'str',
            range: [0, 200]
        }}
    ]
};
//店面管理-店面列表
App.util.ns('Admin.Storefront.Storefront');
App.pages.add((function(){
    var NS = Admin.Storefront.Storefront;
    var page = new App.Page({
        name: 'storefront/storefront/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-gg"></i>',
            content: '店面管理'
        }, {
            content: '店面列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/storefront/storefront',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [1, '上线'],
                    [2, '下线']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.storefront.storefront.create'},
                {parent: 'view', permission: 'op:admin.storefront.storefront.detail'},
                {parent: 'edit', permission: 'op:admin.storefront.storefront.update'},
                {parent: 'drop', permission: 'op:admin.storefront.storefront.delete'},
                {type: 'inline', permission: 'op:admin.storefront.storefront.online', name: '上线', operation: {type: 'change', url: 'online'}, conditions: [['status', '2']]},
                {type: 'inline', permission: 'op:admin.storefront.storefront.offline', name: '下线', operation: {type: 'change', url: 'offline'}, conditions: [['status', '1']]},
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.storefront.storefront.multiOnline', name: '上线', operation: {type: 'change', url: 'multiOnline', confirm: true}},
                    {type: 'multi', permission: 'op:admin.storefront.storefront.multiOffline', name: '下线', operation: {type: 'change', url: 'multiOffline', confirm: true}}
                ], permission:[
                    'op:admin.storefront.storefront.multiOnline',
                    'op:admin.storefront.storefront.multiOffline'
                ]},
                {parent: 'multiDrop', permission: 'op:admin.storefront.storefront.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.storefront.storefront.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//店面管理-商品排期列表-配置文件
App.util.ns('Admin.Storefront.Schedule');
Admin.Storefront.Schedule.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '店面', width: '120px', value: function(item){
            return item.storefront ? item.storefront.name : '-- --';
        }},
        {name: '柜体', width: '190px', value: function(item){
            return item.cabinet ? item.cabinet.name : '-- --';
        }},
        {name: '预期开始时间', width: '90px', value: function(item){
            return App.util.formator.date(item.start_time);
        }},
        {name: '预期结束时间', width: '90px', value: function(item){
            return App.util.formator.date(item.end_time);
        }},
        {name: '状态', width: '120px',value: function(item){
            switch (item.status+'') {
                case '0':
                    return '待更新柜体商品';
                case '1':
                    return '上线';
                case '2':
                    return '下线';
            }
        }},
        {name: '创建日期', width: '90px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'date', name: 'start_time', title: '开始时间', required: true},
        {type: 'date', name: 'end_time', title: '结束时间', required: true},
        {type: 'chosen', name: 'storefront_id', title: '店面',required: true,
            items: App.models.get('storefront-all'),
            item_key: 'id',
            item_name: 'name',
            value_key: 'id',
            rule:{
                type: 'num',
                range: [1, 10]
            },
            onChange:function (self) {
                var cabinets = App.models.get('cabinets-all');
                var cabinets_index = [];
                for (var i=0;i<cabinets.data.length;i++) {
                    var cabinet = cabinets.data[i];
                    if(cabinet.storefront_id == self.value()){
                        cabinets_index.push([cabinet.id,cabinet.name]);
                    }
                }
                self.form.formItems['cabinet_id'].config.items = cabinets_index;
                self.form.formItems['cabinet_id'].flush();
            },
        },
        {type: 'chosen', name: 'cabinet_id', title: '柜体',required: true,
            items: App.models.get('cabinets-all'),
            // item_key: 'id',
            // item_name: 'name',
            // value_key: 'id',
            rule:{
                type: 'num',
                range: [1, 10]
            }
        },
        {type: 'selectLists', name: 'theme_id', title: '专题', required: true,
            data_id: 'id',
            data_name: function(item){
                return item.id+':'+item.name;
            },
            dataTable: {
                baseUrl: '/admin/goods/jmtheme',
                dataUrl: 'lists?status=1',
                data_id: 'id',
                data_name: 'name',
                table: {
                    id: 'id',
                    main: 0,
                    columns: [
                        {name: '专题名', value: 'name'}
                    ]
                },
                filter: [
                    {type: 'keywords'}
                ],
                height: '720px'
            }
        }
    ]
};
//店面管理-排期列表
App.util.ns('Admin.Storefront.Schedule');
App.pages.add((function(){
    var NS = Admin.Storefront.Schedule;
    var page = new App.Page({
        name: 'storefront/schedule/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-gg"></i>',
            content: '店面管理'
        }, {
            content: '商品排期'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/storefront/schedule',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [0, '待更新柜体商品'],
                    [1, '上线'],
                    [2, '下线']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.storefront.schedule.create'},
                //{parent: 'view', permission: 'op:admin.storefront.schedule.detail'},
                {parent: 'edit', permission: 'op:admin.storefront.schedule.update'},
                {type: 'inline', permission: 'op:admin.storefront.schedule.offline',
                    name: '下线',
                    operation: {type: 'change', url: 'offline'},
                    conditions: [['status', '1']]
                },
                {
                    type: 'inline',
                    name: '格子分布',
                    icon: '<i class="fa fa-random"></i>',
                    floatable: true,
                    permission: 'gp:admin/storefront/schedule',
                    operation: function(dataTable, schedule){
                        var win = dataTable.wins.get('schedulegoods').show();
                        win.changeSchedule(schedule);
                        win.show();
                    }
                },
                {type: 'inline', permission: 'op:admin.storefront.schedule.applicationx', name: '应用',
                    operation: {type: 'change', url: 'applicationx'},
                    conditions: [['status', '0']]
                },
                {parent: 'drop', permission: 'op:admin.storefront.schedule.delete'},
                {parent: 'multiDrop', permission: 'op:admin.storefront.schedule.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.storefront.schedule.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.Schedulegoods(dataTable), 'schedulegoods');
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//店面管理-店面里的柜子的格子分布
App.util.ns('Admin.Storefront.Schedule');
Admin.Storefront.Schedule.Schedulegoods = function(dataTable){
    var win = new App.Win({
        name: 'schedulegoods',
        title: '格子分布',
        width: '720px'
    });
    //列表
    win.dataTable = new App.DataTable({
        baseUrl: '/admin/cabinet/cell',
        dataUrl: 'lists',
        table: {
            id: 'id',
            main: 1,
            showId: false,
            withSelect: false,
            columns: [
                {name: '位置', width: '90px', value: function(item){
                    return item.row + ' 行，' + item.col + ' 列';
                }},
                {name: '原商品', width: '90px', value: function(item){
                    var name = item.goods ? item.goods.name : '未分配';
                    return $('<span style="margin: 0 6px">'+name+'</span>');
                }},
                {name: '调换商品', width: '350px', value: function(item){
                    var selector = new App.Form.SelectLists({
                        type: 'selectLists',
                        name: 'id',
                        title: '期望商品',
                        data_id: 'goods_id',
                        width: '600px',
                        data_name: function(item){
                            return item.id+': '+item.name;
                        },
                        dataTable: {
                            baseUrl: '/admin/goods/goods',
                            dataUrl: 'lists?status=1',
                            data_id: 'id',
                            data_name: 'name',
                            table: {
                                id: 'id',
                                main: 0,
                                columns: [
                                    {name: '商品名', value: 'name'}
                                ]
                            },
                            filter: [
                                {type: 'keywords'}
                            ]
                        },
                        detail: {
                            form: {
                                items: App.util.copy(Admin.Goods.Goods.Conf.form)
                            }
                        }
                    });
                    selector.dataTable.win.fix(win.frame);
                    if(selector.detail){
                        selector.detail.win.fix(win.frame);
                    }

                    var goodsjson =win.schedule.goods_json;
                    if(goodsjson){
                        var goodsArr = JSON.parse(goodsjson);
                        for(var i=0;i<goodsArr.length;i++){
                            if(goodsArr[i].id == item.id){
                                selector.change(goodsArr[i].target.id, goodsArr[i].target.name, goodsArr[i].target);
                                break;
                            }
                        }
                    }
                    return selector.frame;
                }},
            ]
        },
        afterLoadData: function(self){
            self.frame.find('tbody td').css({padding: '0'});
        },
        after: function(self){
            self.frame.find('> .header').remove();
            self.frame.find('.data-table').addClass('table-bordered').removeClass('table-hover');
            self.fix(win.contentContainer);
        }
    });
    win.changeSchedule = function(schedule){
        win.schedule = schedule;
        win.setTitle('格子分布 - '+schedule.name);
        win.dataTable.param.set('cabinet_id', schedule.cabinet_id);
        win.dataTable.loadData();
        return win;
    };

    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">提交</a>');
        saveBtn.click(function(){
            var goodsJson = [];
            win.dataTable.frame.find('tbody tr').each(function(){
                var target = $(this).find('input.select-lists-data').val();
                var item = JSON.parse($(this).attr('data-data'));
                item.target = target ? JSON.parse(target) : '';
                goodsJson.push(item);
            });
            App.util.request.postData({
                url: '/admin/storefront/schedule/updateGoodJsonFeild',
                data: {
                    id: win.schedule.id,
                    goods_json: JSON.stringify(goodsJson)
                },
                loading: new App.Loading(win.contentContainer),
                success: function(){
                    dataTable.loadData(true);
                    App.util.hint.toast({
                        type: 'ok',
                        text: '提交成功'
                    }).delay(500, function(){
                        win.hide();
                    });
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};
//企业管理-企业列表-配置文件
App.util.ns('Admin.Enterprise.Enterprise');
Admin.Enterprise.Enterprise.Conf = {
    columns: [
        {name: '企业名称', value: 'name'},
        {name: '联系人', width: '100px', value: 'contact_name'},
        {name: '联系电话', width: '100px', value: 'contact_tel'},
        {name: '状态', width: '80px', value: function(item){
            switch (item.status+'') {
                case '0':
                    return '停用';
                case '1':
                    return '正常';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '企业名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'img', name: 'logo', title: '企业Logo',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'input', name: 'contact_name', title: '联系人员', rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'input', name: 'contact_tel', title: '联系电话', rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'textarea', name: 'rule', title: '奖励规则'},
        {type: 'textarea', name: 'introduction', title: '企业介绍',maxLength: 500, rule: {
            type: 'str',
            range: [0, 500]
        }},
    ]
};

//财务管理-定价
App.util.ns('Admin.Enterprise.Enterprise.Form');
Admin.Enterprise.Enterprise.Form.Rewardrules = function(config){
    this.config = config;
    this.name = this.config.name;
    this.form = null;
    this.frame = null;
    this.items = [];
    this.mainItem = null;
    //初始化
    this.init();
};
Admin.Enterprise.Enterprise.Form.Rewardrules.prototype = {
    constructor: Admin.Enterprise.Enterprise.Form.Rewardrules,
    init: function(){
        var self = this;
        this.frame = $([
            '<div class="program-epg-container">',
            '   <div class="item main">',
            '       <div class="input-group" style="width:100%">',
            '           <input type="text" class="form-control title" placeholder="标题"> <br><br> ',
            //'           <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            '           <input type="text" class="form-control list" placeholder="规则">',
            // '           <span class="input-group-addon" style="border-left: none;border-right: none;">></span>',
            // '           <input type="text" class="form-control unit" placeholder="计费单位">',
            // '           <span class="input-group-addon" style="border-left: none;border-right: none;">:</span>',
            // '           <input type="text" class="form-control price" placeholder="单位价格">',
            '           <span class="input-group-btn">',
            '               <button class="btn btn-default btn-sm btn-add" type="button" style="border-radius: 0;"><i class="fa fa-plus"></i></button>',
            '           </span>',
            '       </div>',
            '       <span class="form-static" style="display: none;"></span>',
            '   </div>',
            '</div>'
        ].join(''));
        this.frame.find('.title').css({float: 'left', width: '90px', height: '30px'});
        //this.frame.find('.input-group-addon').css({float: 'left', width: '30px', height: '30px'});
        this.frame.find('.list').css({float: 'left', width: '90px', height: '30px'});
        // this.frame.find('.unit').css({float: 'left', width: '90px', height: '30px'});
        // this.frame.find('.price').css({float: 'left', width: 'calc(100% - 390px)', height: '30px'});
        this.frame.find('.input-group-btn').css({float: 'left'});
        this.frame.find('.btn-add').click(function(){
            self.getItem().appendTo(self.frame);
        });
        return this;
    },
    setForm: function(form){
        this.form = form;
    },
    getItem: function(){
        this.itemCount += 1;
        var self = this;
        var item = $([
            '<div class="item">',
            '    <div class="input-group" style="width:100%">',
            // '        <input type="text" class="form-control title" placeholder="标题">',
            // '        <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            '        <input type="text" class="form-control list" placeholder="规则">',
            // '        <span class="input-group-addon" style="border-left: none;border-right: none;">></span>',
            // '        <input type="text" class="form-control unit" placeholder="计费单位">',
            // '        <span class="input-group-addon" style="border-left: none;border-right: none;">:</span>',
            // '        <input type="text" class="form-control price" placeholder="单位价格">',
            '        <span class="input-group-btn">',
            '            <button class="btn btn-default btn-sm btn-drop" type="button" style="border-radius: 0;"><i class="fa fa-times"></i></button>',
            '        </span>',
            '    </div>',
            '    <span class="form-static" style="display: none;"></span>',
            '</div>'
        ].join(''));
        //item.find('.title').css({float: 'left', width: '90px', height: '30px'});
        //item.find('.input-group-addon').css({float: 'left', width: '30px', height: '30px'});
        item.find('.list').css({float: 'left', width: '90px', height: '30px'});
        // item.find('.unit').css({float: 'left', width: '90px', height: '30px'});
        // item.find('.price').css({float: 'left', width: 'calc(100% - 390px)', height: '30px'});
        item.find('.input-group-btn').css({float: 'left'});
        item.find('.btn-drop').click(function(){
            item.remove();
        });
        return item;
    },

    change: function(val){//改变
        this.reset();
        val = JSON.parse(val) ? JSON.parse(val) : '';
        var title = val.title ? val.title : '';
        this.frame.find('.item.main .title').val(title);

        for(var i in val){
            var item = val[i];
            var list = item ? item : '';
            //var price = item['price'] ? item['price'] : '';
            //var title = item['title'] ?item['title'] : '';
            //var list = item['list'] ? item['list'] : '';
            //var unit = item['unit'] ? item['unit'] : '';
            if(i+'' === '0'){
                //this.frame.find('.item.main .price').val(price);

                this.frame.find('.item.main .list').val(list);
                //this.frame.find('.item.main .unit').val(unit);
            }else{
                var itemObj = this.getItem();
                //itemObj.find('.price').val(price);
                //itemObj.find('.title').val(title);
                itemObj.find('.list').val(list);
                //itemObj.find('.unit').val(unit);
                itemObj.appendTo(this.frame);
            }
        }
        return this;
    },
    view: function(){//查看
        this.flushView();
        this.frame.find('.item > .input-group').hide();
        this.frame.find('.item > .form-static').show();
        return this;
    },
    flushView: function(){
        var text1 = ' <span style="color: blue;">'+this.frame.find('.title').val() + '</span> ';
        $(this).find('.form-static').html('<span style="font-size: 13px;">'+text1+'</span>');
        this.frame.find('.item').each(function(){
            //var text = '从第 <span style="color: blue;">'+$(this).find('.begin-time').val() + '</span> 分到第 <span style="color: blue;">' + $(this).find('.end-time').val()+'</span> 分，每 <span style="color: blue;">'+$(this).find('.unit').val()+'</span> 分 <span style="color: red;">';
            //text += $(this).find('.price').val()+'</span> 元';
            var text2 = ' <span style="color: blue;">' + $(this).find('.list').val()+'</span>'+'<br>';
            $(this).find('.form-static').html('<span style="font-size: 13px;">'+text2+'</span>');
        });

    },
    reset: function(){
        this.frame.find('.item').each(function(){
            if(!$(this).hasClass('main')){
                $(this).remove();
            }
        });
        this.frame.find('.item.main').find('select').val('').change();
        this.frame.find('.item.main').find('input').val('').change();
        this.frame.find('.item > .input-group').show();
        this.frame.find('.item > .form-static').hide();
        return this;
    },
    edit: function(){
        this.frame.find('.item > .input-group').show();
        this.frame.find('.item > .form-static').hide();
        return this;
    },
    value: function(){
        var self = this;
        var data = [];

        var title = this.frame.find('.title').val();
        data.pus({
            title: title,
        });
        this.frame.find('.item').each(function(){
            //var price = $(this).find('.price').val();
            //var title = $(this).find('.title').val();
            var list = $(this).find('.list').val();
            //var unit = $(this).find('.unit').val();
            data.push({
                //price: price,
                //title: title,
                list: list,
                //unit: unit
            });
        });
        return JSON.stringify(data);
    }, 
    enable: function(){
        this.frame.find('select').prop('disabled', false);
        this.frame.find('input').prop('disabled', false);
        return this;
    },
    disable: function(){
        this.frame.find('select').prop('disabled', true);
        this.frame.find('input').prop('disabled', true);
        return this;
    },
    validate: function(){
        var rs = true;
//        this.frame.find('.input-group').each(function(){
//            var epgId = $(this).find('select').val();
//            var times = $(this).find('input').val();
//            if((epgId.length < 1) && (times.length > 1)){
//                $(this).find('select').addClass('error').one('change', function(){
//                    $(this).removeClass('error');
//                });
//                rs = false;
//            }else if((epgId.length > 1) && (times.length < 1)){
//                $(this).find('input').addClass('error').one('change', function(){
//                    $(this).removeClass('error');
//                });
//                rs = false;
//            }
//        });
        return rs; 
    },
    onChange: function(){
        if(this.config.onChange){
            this.config.onChange(this);
        }
    },
    destroy: function(){
        this.frame.remove();
    }
};
//添加到库
App.Form.lib['admin-enterprise-rule-rewardrules'] = Admin.Enterprise.Enterprise.Form.Rewardrules;
//企业管理-企业列表
App.util.ns('Admin.Enterprise.Enterprise');
App.pages.add((function(){
    var NS = Admin.Enterprise.Enterprise;
    var page = new App.Page({
        name: 'enterprise/enterprise/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-handshake-o"></i>',
            content: '企业管理'
        }, {
            content: '企业列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/enterprise/enterprise',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '80px', items: [
                    [0, '停用'],
                    [1, '正常']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.enterprise.enterprise.create'},
                {parent: 'view', permission: 'op:admin.enterprise.enterprise.detail'},
                {parent: 'edit', permission: 'op:admin.enterprise.enterprise.update'},
                {type: 'inline', permission: 'gp:admin/enterprise/enterprise', name: '企业员工',
                    operation: function(dataTable, enterprise){
                        App.nav.open('enterprise/personnel/index', {
                            enterprise_id: enterprise.id,
                            enterprise_name: enterprise.name
                        });
                    }
                },
                {type: 'inline', permission: 'op:admin.enterprise.enterprise.open',
                    name: '开启', operation: {type: 'change', url: 'open'},
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.enterprise.enterprise.close',
                    name: '关闭', operation: {type: 'change', url: 'close'},
                    conditions: [['status', '1']]
                },
                {parent: 'drop', permission: 'op:admin.enterprise.enterprise.delete'},
                {parent: 'multiDrop', permission: 'op:admin.enterprise.enterprise.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.enterprise.enterprise.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form),
                    onChange: function(form, data){
                        var htmljson = '';
                        var rule=data.rule;
                        if(!rule){
                            htmljson = '暂无信息';
                        }else{
                            rule = JSON.parse(rule);
                            htmljson += rule.title+'<br>';
                            var rulelist = rule.list;
                            for (var i =0;i<rulelist.length;i++){
                                htmljson += rulelist[i]+'<br>';
                            }
                        }
                        form.formItems['rule'].change(htmljson);
                    }
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//企业管理-企业员工-配置文件
App.util.ns('Admin.Enterprise.Personnel');
Admin.Enterprise.Personnel.Conf = {
    columns: [
        {name: '员工名称', value: 'name'},
        {name: '企业名称', width: '150px', value: function(item){
            return item.enterprise ? item.enterprise.name : '-- --';
        }},
        {name: '性别', width: '100px', value: function(item){
            switch (item.gender+'') {
                case '0':
                    return '未知';
                case '1':
                    return '男';
                case '2':
                    return '女';
            }
        }},
        {name: '手机号', width: '100px',value: 'phone'},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '员工名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'radio', name: 'gender', title: '性别',
            items: [
                ['0', '未知'],
                ['1', '男'],
                ['2', '女']
            ],
            defaults: '0'
        },
        {type: 'input', name: 'phone', title: '手机号', rule: {
            type: 'str',
            range: [0, 40]
        }}
    ]
};
//商品管理-商品即秒排期列表
App.util.ns('Admin.Enterprise.Personnel');
App.pages.add((function(){
    var NS = Admin.Enterprise.Personnel;
    var page = new App.Page({
        name: 'enterprise/personnel/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/enterprise/personnel',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'gender', title: '性别', width: '80px', items: [
                    [0, '未知'],
                    [1, '男'],
                    [2, '女']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.enterprise.personnel.create'},
                {type: 'globe', permission: 'op:admin.enterprise.personnel', name: '导入表格',
                    operation: function(dataTable){
                    dataTable.wins.get('multiImportWin').show();}
                },
                {parent: 'view', permission: 'op:admin.enterprise.personnel.detail'},
                {parent: 'edit', permission: 'op:admin.enterprise.personnel.update'},
                {parent: 'drop', permission: 'op:admin.enterprise.personnel.delete'},
                {parent: 'multiDrop', permission: 'op:admin.enterprise.personnel.multiDelete'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form),
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.MultiImport(dataTable), 'multiImportWin');
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
    });
    //页面打开
    page.showStack.add('openPage', function(){
        if(this.params){
            var params = this.params;
            //设置面包屑导航
            this.setBreadcrumb([{
                icon: '<i class="fa fa-crosshairs"></i>',
                content: '企业与企业员工'
            }, {
                content: '员工管理',
                action: function(){
                    App.nav.back();
                }
            }, {
                active: true,
                content: '员工所属企业 - ' + params['enterprise_name']
            }]);
            //设置参数
            for(var i in params){
                this.dataTable.param.set(i, params[i]);
            }
            if(this.dataTable.paginator){
                this.dataTable.paginator.currentPage = 1;
            }
            //加载数据
            this.dataTable.loadData();
        }
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//企业管理-员工管理-导入表格
App.util.ns('Admin.Enterprise.Personnel');
Admin.Enterprise.Personnel.MultiImport = function(dataTable){
    var multiImporter = {
        data: [],
        items: [
        ],
        frame: function(){
            var self = this;
            this.frame = $([
                '<div class="video-multi-upload-container">',
                '    <div class="add-btn-container">',
                '        <button class="btn btn-success btn-sm add-btn"><i class="fa fa-plus"></i> 导入企业员工名单</button>',
                '        <input class="upload-file" type="file" style="display: none;"/>',
                '    </div>',
                '</div>'
            ].join(''));
            //console.log(this);
            return this;
        },
        dataTable: function(){
            var self = this;
            return this;
        },
        init: function(){
            var self = this;
            self.frame().dataTable();
            //数据表格
            self.frame.prepend(self.dataTable.container);
            this.frame.find('.add-btn').click(function(){
                self.frame.find('.upload-file').click();
            });
            this.frame.find('.upload-file').change(function(){
                if(this.files.length > 0){
                    self.addFile(this.files[0]);
                }
            });
            return this;
        },
        addFile: function(file){
            if(file.size > 8388608){
                App.util.hint.alert({
                    text: '文件不能超过8Mb'
                });
                return;
            }
            var self = this;
            var enterpriseId = dataTable.param.data.enterprise_id;
            var xhr = new XMLHttpRequest();
            xhr.open('POST', dataTable.url('importCheck'), true);
            var formData, startDate = new Date().getTime();
            formData = new FormData();
            formData.append('file', file);
            formData.append('enterpriseId', enterpriseId);

            //进度
            var toast = App.util.hint.toast({
                type: 'loading',
                text: '正在上传数据，请稍后...',
                lock: true
            });
            //成功
            xhr.onreadystatechange = function() {
                if(xhr.readyState === 4) {
                    toast.close();
                    if(xhr.status !== 200){//网络错误
                        //错误提示
                        App.util.hint.toast({
                            type: 'error',
                            text: '服务器错误'
                        }).delay(3000);
                        return ;
                    }
                    var dataRaw = JSON.parse(xhr.responseText);
                    if(dataRaw.status === '0'){
                        App.util.hint.toast({
                            type: 'ok',
                            text: '导入成功，手动刷新'
                        }).delay(3000);
                        win.hide();
                    }else{//其它错误
                        //错误提示
                        App.util.hint.toast({
                            type: 'error',
                            text: dataRaw.msg
                        }).delay(3000);
                    }
                }
            };
            xhr.send(formData);
        },
    }.init();
    var win = new App.Win({name: 'multi_import', width: '800px'});
    win.setTitle('导入表格');
    win.setContent(multiImporter.frame);
    win.hide();
    return win;
};
//供应商管理-供应商列表-配置文件
App.util.ns('Admin.Supplier.Supplier');
Admin.Supplier.Supplier.Conf = {
    columns: [
        {name: '供应商名称', value: 'name'},
        {name: '登录账号', width: '200px', value: function(item){
            return item.admin ? item.admin.username : '无';
        }},
        {name: '联系人', width: '120px', value: 'contact_name'},
        {name: '联系电话', width: '120px', value: 'contact_tel'},
        {name: '状态', width: '80px', value: function(item){
            switch (item.status+'') {
                case '0':
                    return '停用';
                case '1':
                    return '正常';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'username', title: '登录账号', required: true, rule: {
            type: 'str',
            range: [1, 100]
        }},
        [
            {type: 'password', name: 'password', title: '登录密码', required: true, rule: {
                type: 'str',
                range: [1, 100]
            }},
            {type: 'password', name: 're_password', title: '确认密码', required: true, rule: function(self){
                return self.form.formItems['password'].value() === self.value();
            }}
        ],
        {type: 'input', name: 'name', title: '供应商名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'input', name: 'contact_name', title: '联系人',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'input', name: 'contact_tel', title: '联系电话', rule: {
            type: 'num'
        }},
        {type: 'textarea', name: 'introduction', title: '简介', maxLength: 200,
            rule: {
            type: 'str',
            range: [0, 200]
        }}
    
    ]
};
//供应商管理-供应商列表
App.util.ns('Admin.Supplier.Supplier');
App.pages.add((function(){
    var NS = Admin.Supplier.Supplier;
    var page = new App.Page({
        name: 'supplier/supplier/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-support"></i>',
            content: '供应商管理'
        }, {
            content: '供应商列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/supplier/supplier',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.supplier.supplier.create'},
                {parent: 'view', permission: 'op:admin.supplier.supplier.detail'},
                {parent: 'edit', permission: 'op:admin.supplier.supplier.update'},
                {type: 'inline', permission: 'op:admin.supplier.supplier', name: '重置密码', operation: function(dataTable, supplier){
                    var win = dataTable.wins.get('resetPassword');
                    win.form.change({password: '', re_password: '', id: supplier.id});
                    win.setTitle('重置密码 - '+supplier.name+'（'+supplier.name+'）');
                    win.show();
                }},
                {type: 'inline', permission: 'op:admin.supplier.supplier.open', name: '开启', operation: {type: 'change', url: 'open'}, conditions: [['status', '0']]},
                {type: 'inline', permission: 'op:admin.supplier.supplier.close', name: '禁用', operation: {type: 'change', url: 'close'}, conditions: [['status', '1']]},
                {parent: 'drop', permission: 'op:admin.supplier.supplier.delete'},
                {parent: 'multiDrop', permission: 'op:admin.supplier.supplier.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.supplier.supplier.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form),
                    add: 'all',
                    edit: 'except:username,password,re_password',
                    view: 'except:username,password,re_password'
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.ResetPassword(dataTable), 'resetPassword');
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//大客户管理-客户列表-重置密码
App.util.ns('Admin.Supplier.Supplier');
Admin.Supplier.Supplier.ResetPassword = function(dataTable){
    var win = new App.Win({name: 'reset_password', width: '350px'});
    //表单
    var form = new App.Form({items: [
        {type: 'password', name: 'password', title: '新密码', required: true, rule: {
            type: 'str',
            range: [6, 100]
        }},
        {type: 'password', name: 're_password', title: '确认密码', required: true, rule: function(self){
            return self.form.formItems['password'].value() === self.value();
        }},
        {type: 'hidden', name: 'id'}
    ]});
    form.fix(win.contentContainer);
    win.form = form;
    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">保存</a>');
        saveBtn.click(function(){
            if(!form.validate()){
                return ;
            }
            dataTable.postData({
                url: 'resetPassword',
                alert: '保存成功！',
                reload: false,
                data: form.getData(),
                after: function(){
                    win.hide();
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};
//货柜与商品-商品列表-配置文件
App.util.ns('Admin.Goods.Goods');
Admin.Goods.Goods.Conf = {
    columns: [
        {name: '商品名', value: 'name',width: '300px',},
        {name: '进货价', width: '60px',value: 'price_cost'},
        {name: '限价', width: '60px',value: 'fixed_price'},
        {name: '商城价', width: '60px',value: 'price_original'},
        {name: '走路抵金', width: '65px',value: 'moneylimit'},
        //{name: '活动价', width: '80px',value: 'price_lower'},
        {name: '体验价', width: '60px',value: 'price_lowest'},
        {name: '体验抵金', width: '65px',value: 'experience_payment'},
        {name: '供应商', width: '100px', value:function(item){
            return item.supplier ? item.supplier.name : '-- --';
        }},
        {name: '品牌名', width: '60px',value: function (item) {
            return item.brand ? item.brand.name : '-- --';
        }},
        {name: '型号', width: '60px',value: 'models'},
        {name: '库存', width: '60px',value: 'inventory'},
        {name: '卖出数量', width: '65px',value: 'sell_total'},
        {name: '关键词', width: '100px',value: 'classify'},
        {name: '可否体验', width: '65px',value: function(item){
            switch (item.is_experience+'') {
                case '0':
                    return '可体验';
                case '1':
                    return '不可体验';
            }
        }},
        {name: '是否限购', width: '65px',value: function(item){
            switch (item.buylimit+'') {
                case '0':
                    return '否';
                case '1':
                    return '是';
            }
        }},
        {name: '是否仅限新用户', width: '100px',value: function(item){
            switch (item.is_buy+'') {
                case '0':
                    return '否';
                case '1':
                    return '是';
            }
        }},
        {name: '状态', width: '60px',value: function(item){
            switch (item.status+'') {
                case '0':
                    return '下线';
                case '1':
                    return '在线';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', required: true, maxLength: 50, rule: {
            type: 'str',
            range: [1, 50]
        }},
        {type: 'img', name: 'icon', title: '图标',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'video', name: 'video', title: '介绍视频',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'input', name: 'price_cost', title: '进货价', rule: {
            type: 'str',
            range: [0, 30]
        }},
        {type: 'input', name: 'fixed_price', title: '限价', rule: {
            type: 'str',
            range: [0, 30]
        }},
        {type: 'input', name: 'price_original', title: '商城价', required: true,
            comment: '请输入带两位小数的数字。如88.00',
            rule: {
                type: 'float',
                range: [1],
                decimal: [2, 2]
        }},
        {type: 'input', name: 'moneylimit', title: '走路抵金',required: true, rule: {
            type: 'str',
            range: [0,100]
        }},
        // {type: 'input', name: 'price_lower', title: '活动价', required: true,
        //     comment: '同上',
        //     rule: {
        //         type: 'float',
        //         range: [1],
        //         decimal: [2, 2]
        // }},
        {type: 'input', name: 'price_lowest', title: '体验价', required: true,
            comment: '请输入带两位小数的数字。如88.00',
            rule: {
                type: 'float',
                range: [1],
                decimal: [2, 2]
        }},
        {type: 'input', name: 'experience_payment', title: '体验抵金',required: true, rule: {
            type: 'str',
            range: [0,100]
        }},
        {type: 'chosen', name: 'supplier_id', title: '供应商',
            items: App.models.get('supplier-all'),
            item_key: 'id',
            item_name: 'name',
            rule: {
                type: 'num',
                range: [0, 250]
        }},
        {type: 'selectLists', name: 'brand_id', title: '品牌',
            data_id: 'id',
            data_name: function(item){
                return item.id+':'+item.name;
            },
            dataTable: {
                baseUrl: '/admin/goods/brand',
                dataUrl: 'lists?status=1',
                data_id: 'id',
                data_name: 'name',
                table: {
                    id: 'id',
                    main: 0,
                    columns: [
                        {name: '品牌名', value: 'name'}
                    ]
                },
                filter: [
                    {type: 'keywords'}
                ],
                height: '720px'
            }
        },
        {type: 'tags', name: 'models', title: '型号', rule: {
            type: 'str',
            range: [0,200]
        }},
        {type: 'input', name: 'inventory', title: '库存',required: true, rule: {
            type: 'num'
        }},
        {type: 'input', name: 'sell_total', title: '卖出数量',required: true, rule: {
            type: 'num'
        }},
        {type: 'input', name: 'score', title: '评分',
            comment: '输入“5.0,5.0,4.5,5.0(英文逗号)”  分别对应 “颜值，实用，做工，材质”，(最高5.0分)',
            rule: {
                type: 'str',
                range: [0, 50]
        }},
        {type: 'checkbox', name: 'types', title: '类型', required: true,
            items: App.models.get('goodstypes'),
            item_key: 'id',
            item_name: 'name',
            rule: {
                type: 'str',
                range: [1, 250]
        }},
        {type: 'tags', name: 'classify', title: '关键词', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 200]
        }},
        {type: 'admin-goods-spec-specifications', name: 'spec', title: '规格',
            comment: '例如：颜色  红,黄(必须用英文逗号)',
        },
        {type: 'radio', name: 'is_experience', title: '可否体验', required: true,
            items: [
                ['0', '可体验'],
                ['1', '不可体验']
            ],
            defaults: '0'
        },
        {type: 'radio', name: 'buylimit', title: '是否限购', required: true,
            items: [
                ['0', '否'],
                ['1', '是']
            ],
            defaults: '0'
        },
        {type: 'radio', name: 'is_buy', title: '是否仅限新用户购买', required: true,
            items: [
                ['0', '否'],
                ['1', '是']
            ],
            defaults: '0'
        },
        {type: 'imgs', name: 'posters', title: '轮播图', rule: {
            type: 'str',
            // range: [0, 1000]
        }},
        {type: 'imgs', name: 'imgs', title: '商品详情图', rule: {
            type: 'str',
            // range: [0, 1000]
        }},
        {type: 'imgs', name: 'imgs_parameter', title: '购物须知图', rule: {
            type: 'str',
            // range: [0, 1000]
        }},
        {type: 'textarea', name: 'discription', title: '商品简介',maxLength: 100, rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'textarea', name: 'introduction', title: '功能介绍',maxLength: 500, rule: {
            type: 'str',
            range: [0, 500]
        }},
        // {type: 'textarea', name: 'goods_info_json', title: '其他信息', maxLength: 2000,
        //     rule: {
        //     type: 'str',
        //     range: [0, 4000]
        // }},
    ]
};
//商品管理-规格
App.util.ns('Admin.Goods.Goods.Form');
Admin.Goods.Goods.Form.Specifications = function(config){
    this.config = config;
    this.name = this.config.name;
    this.form = null;
    this.frame = null;
    this.items = [];
    this.mainItem = null;
    //初始化
    this.init();
};
Admin.Goods.Goods.Form.Specifications.prototype = {
    constructor: Admin.Goods.Goods.Form.Specifications,
    init: function(){
        var self = this;
        this.frame = $([
            '<div class="program-epg-container">',
            '   <div class="item main">',
            '       <div class="input-group" style="width:100%">',
            '           <input type="text" class="form-control spec" placeholder="规格(例如：颜色)">',
            '           <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            '           <input type="text" class="form-control param" placeholder="参数(例如：红色,黄色)">',
            //'           <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            // '           <input type="text" class="form-control unit" placeholder="计费单位">',
            // '           <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            // '           <input type="text" class="form-control price" placeholder="价格">',
            '           <span class="input-group-btn">',
            '               <button class="btn btn-default btn-sm btn-add" type="button" style="border-radius: 0;"><i class="fa fa-plus"></i></button>',
            '           </span>',
            '       </div>',
            '       <span class="form-static" style="display: none;"></span>',
            '   </div>',
            '</div>'
        ].join(''));
        this.frame.find('.spec').css({float: 'left', width: '115px', height: '30px'});
        this.frame.find('.input-group-addon').css({float: 'left', width: '30px', height: '30px'});
        this.frame.find('.param').css({float: 'left', width: '220px', height: '30px'});
        // this.frame.find('.unit').css({float: 'left', width: '90px', height: '30px'});
        // this.frame.find('.price').css({float: 'left', width: 'calc(100% - 390px)', height: '30px'});
        this.frame.find('.input-group-btn').css({float: 'left'});
        this.frame.find('.btn-add').click(function(){
            self.getItem().appendTo(self.frame);
        });
        return this;
    },
    setForm: function(form){
        this.form = form;
    },
    getItem: function(){
        this.itemCount += 1;
        var self = this;
        var item = $([
            '<div class="item">',
            '    <div class="input-group" style="width:100%">',
            '        <input type="text" class="form-control spec" placeholder="规格">',
            '        <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            '        <input type="text" class="form-control param" placeholder="参数">',
            // '        <span class="input-group-addon" style="border-left: none;border-right: none;">></span>',
            // '        <input type="text" class="form-control unit" placeholder="计费单位">',
            // '        <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            // '        <input type="text" class="form-control price" placeholder="价格">',
            '        <span class="input-group-btn">',
            '            <button class="btn btn-default btn-sm btn-drop" type="button" style="border-radius: 0;"><i class="fa fa-times"></i></button>',
            '        </span>',
            '    </div>',
            '    <span class="form-static" style="display: none;"></span>',
            '</div>'
        ].join(''));
        item.find('.spec').css({float: 'left', width: '115px', height: '30px'});
        item.find('.input-group-addon').css({float: 'left', width: '30px', height: '30px'});
        item.find('.param').css({float: 'left', width: '220px', height: '30px'});
        //item.find('.unit').css({float: 'left', width: '90px', height: '30px'});
        //item.find('.price').css({float: 'left', width: 'calc(100% - 390px)', height: '30px'});
        item.find('.input-group-btn').css({float: 'left'});
        item.find('.btn-drop').click(function(){
            item.remove();
        });
        return item;
    },
    change: function(val){//改变
        this.reset();
        val = JSON.parse(val) ? JSON.parse(val) : '';
        for(var i in val){
            var item = val[i];
            //var price = item['price'] ? item['price'] : '';
            var spec = item['spec'] ? item['spec'] : '';
            var param = item['param'] ?item['param'] : '';
            if(i+'' === '0'){
                //this.frame.find('.item.main .price').val(price);
                this.frame.find('.item.main .spec').val(spec);
                this.frame.find('.item.main .param').val(param);
            }else{
                var itemObj = this.getItem();
                //itemObj.find('.price').val(price);
                itemObj.find('.spec').val(spec);
                itemObj.find('.param').val(param);
                itemObj.appendTo(this.frame);
            }
        }
        return this;
    },
    view: function(){//查看
        this.flushView();
        this.frame.find('.item > .input-group').hide();
        this.frame.find('.item > .form-static').show();
        return this;
    },
    flushView: function(){
        this.frame.find('.item').each(function(){
            var text = '规格： <span style="color: blue;">'+$(this).find('.spec').val() + '</span> ，参数： <span style="color: blue;">' + $(this).find('.param').val()+'</span> ';
            $(this).find('.form-static').html('<span style="font-size: 13px;">'+text+'</span>');
        });
    },
    reset: function(){
        this.frame.find('.item').each(function(){
            if(!$(this).hasClass('main')){
                $(this).remove();
            }
        });
        this.frame.find('.item.main').find('select').val('').change();
        this.frame.find('.item.main').find('input').val('').change();
        this.frame.find('.item > .input-group').show();
        this.frame.find('.item > .form-static').hide();
        return this;
    },
    edit: function(){
        this.frame.find('.item > .input-group').show();
        this.frame.find('.item > .form-static').hide();
        return this;
    },
    value: function(){
        var self = this;
        var data = [];
        this.frame.find('.item').each(function(){
            //var price = $(this).find('.price').val();
            var spec = $(this).find('.spec').val();
            var param = $(this).find('.param').val();
            data.push({
                //price: price,
                spec: spec,
                param: param
            });
        });
        return JSON.stringify(data);
    }, 
    enable: function(){
        this.frame.find('select').prop('disabled', false);
        this.frame.find('input').prop('disabled', false);
        return this;
    },
    disable: function(){
        this.frame.find('select').prop('disabled', true);
        this.frame.find('input').prop('disabled', true);
        return this;
    },
    validate: function(){
        var rs = true;
//        this.frame.find('.input-group').each(function(){
//            var epgId = $(this).find('select').val();
//            var times = $(this).find('input').val();
//            if((epgId.length < 1) && (times.length > 1)){
//                $(this).find('select').addClass('error').one('change', function(){
//                    $(this).removeClass('error');
//                });
//                rs = false;
//            }else if((epgId.length > 1) && (times.length < 1)){
//                $(this).find('input').addClass('error').one('change', function(){
//                    $(this).removeClass('error');
//                });
//                rs = false;
//            }
//        });
        return rs; 
    },
    onChange: function(){
        if(this.config.onChange){
            this.config.onChange(this);
        }
    },
    destroy: function(){
        this.frame.remove();
    }
};
//添加到库
App.Form.lib['admin-goods-spec-specifications'] = Admin.Goods.Goods.Form.Specifications;
//货柜与商品-商品列表
App.util.ns('Admin.Goods.Goods');
App.pages.add((function(){
    var NS = Admin.Goods.Goods;
    var page = new App.Page({
        name: 'goods/goods/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-crosshairs"></i>',
            content: '商品管理'
        }, {
            content: '商品列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/goods',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'is_experience', title: '可否体验', width: '90px', items: [
                    [0, '可体验'],
                    [1, '不可体验']
                ]},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [0, '下线'],
                    [1, '在线']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.goods.create'},
                {type: 'globe', name: '导出', permission: 'op:admin.goods.goods', operation:function (dataTable) {
                    //发请求ajax
                    $.ajax({
                        url: 'admin/goods/goods/multiExport',
                        data: dataTable.filter.data,
                        type: "get",
                        async: false,
                        success: function (returnData) {
                            returnData = JSON.parse(returnData)
                            if(returnData.status == '0'){
                                var $a = $("<a>");
                                $a.attr("href", returnData.data.file);
                                $a.attr("download", returnData.data.filename);
                                $("body").append($a);
                                $a[0].click();
                                $a.remove();
                            }else {
                                App.util.hint.toast({
                                    type: 'error',
                                    text: returnData.msg
                                }).delay(500);
                            }

                        },
                        error: function () {
                            App.util.hint.toast({
                                type: 'error',
                                text: '格式不对'
                            }).delay(500);
                        }
                    });

                }},
                {parent: 'view', permission: 'op:admin.goods.goods.detail'},
                {parent: 'edit', permission: 'op:admin.goods.goods.update'},
                {type: 'inline', permission: 'op:admin.goods.goods.online',
                    name: '上线', operation: {type: 'change', url: 'online'},
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.goods.goods.offline',
                    name: '下线', operation: {type: 'change', url: 'offline'},
                    conditions: [['status', '1']]
                },
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.goods.goods.multiOnline', name: '上线', operation: {type: 'change', url: 'multiOnline', confirm: true}},
                    {type: 'multi', permission: 'op:admin.goods.goods.multiOffline', name: '下线', operation: {type: 'change', url: 'multiOffline', confirm: true}}
                    ], permission:[
                        'op:admin.goods.goods.multiOnline',
                        'op:admin.goods.goods.multiOffline'
                ]},
                {parent: 'drop', permission: 'op:admin.goods.goods.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.goods.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.goods.goods.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            dragSort:{
                permission: 'op:admin.goods.goods.sort',
                url:'sort',
                filed:'sort',
                conditions:[['status', '1']]
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//品牌管理-品牌列表-配置文件
App.util.ns('Admin.Goods.Brand');
Admin.Goods.Brand.Conf = {
    columns: [
        {name: '品牌名称', value: 'name'},
        {name: '品牌介绍', width: '300px', value: 'introduction'},
        {name: '状态', width: '80px', value: function(item){
            switch (item.status+'') {
                case '0':
                    return '停用';
                case '1':
                    return '正常';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '品牌名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'img', name: 'logo', title: '品牌Logo',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'textarea', name: 'introduction', title: '品牌介绍',maxLength: 500, rule: {
            type: 'str',
            range: [0, 500]
        }},
    ]
};

//品牌管理-品牌列表
App.util.ns('Admin.Goods.Brand');
App.pages.add((function(){
    var NS = Admin.Goods.Brand;
    var page = new App.Page({
        name: 'goods/brand/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-crosshairs"></i>',
            content: '品牌管理'
        }, {
            content: '品牌列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/brand',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '80px', items: [
                    [0, '停用'],
                    [1, '正常']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.enterprise.enterprise.create'},
                {parent: 'view', permission: 'op:admin.enterprise.enterprise.detail'},
                {parent: 'edit', permission: 'op:admin.enterprise.enterprise.update'},
                {type: 'inline', permission: 'op:admin.enterprise.enterprise.open',
                    name: '开启', operation: {type: 'change', url: 'open'},
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.enterprise.enterprise.close',
                    name: '关闭', operation: {type: 'change', url: 'close'},
                    conditions: [['status', '1']]
                },
                {parent: 'drop', permission: 'op:admin.enterprise.enterprise.delete'},
                {parent: 'multiDrop', permission: 'op:admin.enterprise.enterprise.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.enterprise.enterprise.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form),
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//货柜与商品-商品列表
App.util.ns('Admin.Goods.Goods');
App.pages.add((function(){
    var NS = Admin.Goods.Goods;
    var page = new App.Page({
        name: 'goods/goods/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-crosshairs"></i>',
            content: '商品管理'
        }, {
            content: '商品列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/goods',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'is_experience', title: '可否体验', width: '90px', items: [
                    [0, '可体验'],
                    [1, '不可体验']
                ]},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [0, '下线'],
                    [1, '在线']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.goods.create'},
                {type: 'globe', name: '导出', permission: 'op:admin.goods.goods', operation:function (dataTable) {
                    //发请求ajax
                    $.ajax({
                        url: 'admin/goods/goods/multiExport',
                        data: dataTable.filter.data,
                        type: "get",
                        async: false,
                        success: function (returnData) {
                            returnData = JSON.parse(returnData)
                            if(returnData.status == '0'){
                                var $a = $("<a>");
                                $a.attr("href", returnData.data.file);
                                $a.attr("download", returnData.data.filename);
                                $("body").append($a);
                                $a[0].click();
                                $a.remove();
                            }else {
                                App.util.hint.toast({
                                    type: 'error',
                                    text: returnData.msg
                                }).delay(500);
                            }

                        },
                        error: function () {
                            App.util.hint.toast({
                                type: 'error',
                                text: '格式不对'
                            }).delay(500);
                        }
                    });

                }},
                {parent: 'view', permission: 'op:admin.goods.goods.detail'},
                {parent: 'edit', permission: 'op:admin.goods.goods.update'},
                {type: 'inline', permission: 'op:admin.goods.goods.online',
                    name: '上线', operation: {type: 'change', url: 'online'},
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.goods.goods.offline',
                    name: '下线', operation: {type: 'change', url: 'offline'},
                    conditions: [['status', '1']]
                },
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.goods.goods.multiOnline', name: '上线', operation: {type: 'change', url: 'multiOnline', confirm: true}},
                    {type: 'multi', permission: 'op:admin.goods.goods.multiOffline', name: '下线', operation: {type: 'change', url: 'multiOffline', confirm: true}}
                    ], permission:[
                        'op:admin.goods.goods.multiOnline',
                        'op:admin.goods.goods.multiOffline'
                ]},
                {parent: 'drop', permission: 'op:admin.goods.goods.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.goods.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.goods.goods.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            dragSort:{
                permission: 'op:admin.goods.goods.sort',
                url:'sort',
                filed:'sort',
                conditions:[['status', '1']]
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//商品管理-商品分类-配置文件
App.util.ns('Admin.Goods.GoodsType');
Admin.Goods.GoodsType.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '状态', width: '90px',value: function(item){
            switch (item.status+'') {
                case '0':
                    return '下线';
                case '1':
                    return '在线';
            }
        }},
        {name: '创建日期', width: '90px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'img', name: 'icon', title: '分类图标',rule: {
            type: 'str',
            range: [0, 255]
        }}
    ]
};
//商品管理-商品分类
App.util.ns('Admin.Goods.GoodsType');
App.pages.add((function(){
    var NS = Admin.Goods.GoodsType;
    var page = new App.Page({
        name: 'goods/goodstype/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-crosshairs"></i>',
            content: '商品管理'
        }, {
            content: '商品分类'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/goodstype',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [0, '下线'],
                    [1, '在线']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.goodstype.create'},
                {parent: 'view', permission: 'op:admin.goods.goodstype.detail'},
                {parent: 'edit', permission: 'op:admin.goods.goodstype.update'},
                {type: 'inline', permission: 'op:admin.goods.goodstype.online',
                    name: '上线',
                    operation: {type: 'change', url: 'online'},
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.goods.goodstype.offline',
                    name: '下线',
                    operation: {type: 'change', url: 'offline'},
                    conditions: [['status', '1']]
                },
                {parent: 'drop', permission: 'op:admin.goods.goodstype.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.goodstype.multiDelete'},
                //{parent: 'oplog', permission: 'op:admin.goods.goodstype.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            dragSort:{
                permission: 'op:admin.goods.goodstype.sort',
                url:'sort',
                filed:'sort',
                conditions:[['status', '1']]
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//商品管理-极秒排期列表-配置文件
App.util.ns('Admin.Goods.JmSchedule');
Admin.Goods.JmSchedule.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '开始时间', width: '120px', value: function(item){
            return App.util.formator.date(item.start_time);
        }},
        {name: '结束时间', width: '120px', value: function(item){
            return App.util.formator.date(item.end_time);
        }},
        {name: '状态', width: '120px',value: function(item){
            switch (item.status+'') {
                case '0':
                    return '未上线';
                case '1':
                    return '上线';
                case '2':
                    return '下线';
            }
        }},
        {name: '创建日期', width: '90px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'date', name: 'start_time', title: '开始时间', required: true},
        {type: 'date', name: 'end_time', title: '结束时间', required: true},
    ]
};
//商品管理-极秒排期列表
App.util.ns('Admin.Goods.JmSchedule');
App.pages.add((function(){
    var NS = Admin.Goods.JmSchedule;
    var page = new App.Page({
        name: 'goods/jmschedule/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-crosshairs"></i>',
            content: '商品管理'
        }, {
            content: '商品排期'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/jmschedule',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [0, '未上线'],
                    [1, '上线'],
                    [2, '下线']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.jmschedule.create'},
                {parent: 'view', permission: 'op:admin.goods.jmschedule.detail'},
                {parent: 'edit', permission: 'op:admin.goods.jmschedule.update'},
                {type: 'inline', permission: 'gp:admin/goods/gsjmschedule', name: '极秒区商品',
                    operation: function(dataTable, jmschedule){
                        App.nav.open('goods/gsjmschedule/index', {
                            schedule_id: jmschedule.id,
                            schedule_name: jmschedule.name
                        });
                    }
                },
                {type: 'inline', permission: 'op:admin.goods.jmschedule.againonline',
                    name: '上线',
                    operation: {type: 'change', url: 'againonline'},
                    conditions: [['status', '2']]
                },
                {type: 'inline', permission: 'op:admin.goods.jmschedule.online',
                    name: '上线',
                    operation: {type: 'change', url: 'online'},
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.goods.jmschedule.offline',
                    name: '下线',
                    operation: {type: 'change', url: 'offline'},
                    conditions: [['status', '1']]
                },
                {parent: 'drop', permission: 'op:admin.goods.jmschedule.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.jmschedule.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.goods.jmschedule.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//商品管理-商品即秒排期-配置文件
App.util.ns('Admin.Goods.GsJmSchedule');
Admin.Goods.GsJmSchedule.Conf = {
    columns: [
        {name: '商品', width: '200px', value: function(item){
            return item.goods ? item.goods.name : '未分配';
        }},
        {name: '排期名', width: '120px', value: function(item){
            return item.jmschedule ? item.jmschedule.name : '未分配';
        }},
        {name: '库存', width: '120px',value: 'inventory'},
        {name: '卖出数量', width: '120px',value: 'sell_total'},
        {name: '价格', width: '120px',value: 'price'},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        // {type: 'chosen', name: 'goods_id', title: '商品',
        //     items: App.models.get('goods-all'),
        //     item_key: 'id',
        //     item_name: 'name',
        //     value_key: 'id'
        // },

        {type: 'selectLists', name: 'goods_id', title: '商品', required: true,
            data_id: 'id',
            data_name: function(item){
                return item.id+':'+item.name;
            },
            dataTable: {
                baseUrl: '/admin/goods/goods',
                dataUrl: 'lists?status=1',
                data_id: 'id',
                data_name: 'name',
                table: {
                    id: 'id',
                    main: 0,
                    columns: [
                        {name: '商品名', value: 'name'},
                        {name: '商品原价', value: 'price_original'},
                        {name: '商品体验价', value: 'price_lowest'},
                        {name: '库存', value: 'inventory'}
                    ]
                },
                filter: [
                    {type: 'keywords'},
                ],
                height: '720px'
            }
        },
        {type: 'input', name: 'inventory', title: '库存', required: true, rule: {
            type: 'num'
        }},
        {type: 'input', name: 'sell_total', title: '卖出数量', required: true, rule: {
            type: 'num'
        }},
        {type: 'input', name: 'price', title: '价格', required: true, rule: {
            type: 'str',
            range: [0, 30]
        }},
    ]
};
//商品管理-商品即秒排期列表
App.util.ns('Admin.Goods.GsJmSchedule');
App.pages.add((function(){
    var NS = Admin.Goods.GsJmSchedule;
    var page = new App.Page({
        name: 'goods/gsjmschedule/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/gsjmschedule',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                //{type: 'keywords'},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.gsjmschedule.create'},
                //{parent: 'view', permission: 'op:admin.goods.gsjmschedule.detail'},
                {parent: 'edit', permission: 'op:admin.goods.gsjmschedule.update'},
                {parent: 'drop', permission: 'op:admin.goods.gsjmschedule.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.gsjmschedule.multiDelete'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form),
                }
            },
            dragSort:{
                permission: 'op:admin.goods.gsjmschedule.sort',
                url:'sort',
                filed:'sort'
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
    });
    //页面打开
    page.showStack.add('openPage', function(){
        if(this.params){
            var params = this.params;
            //设置面包屑导航
            this.setBreadcrumb([{
                icon: '<i class="fa fa-crosshairs"></i>',
                content: '商品与极秒商品排期'
            }, {
                content: '商品管理',
                action: function(){
                    App.nav.back();
                }
            }, {
                active: true,
                content: '极秒商品管理 - ' + params['schedule_name']
            }]);
            //设置参数
            for(var i in params){
                this.dataTable.param.set(i, params[i]);
            }
            if(this.dataTable.paginator){
                this.dataTable.paginator.currentPage = 1;
            }
            //加载数据
            this.dataTable.loadData();
        }
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//商品管理-专题排期列表-配置文件
App.util.ns('Admin.Goods.JmTheme');
Admin.Goods.JmTheme.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '专题简介', width: '350px',value: 'introduction'},
        {name: '状态', width: '120px',value: function(item){
            switch (item.status+'') {
                case '1':
                    return '在线';
                case '2':
                    return '下线';
            }
        }},
        {name: '创建日期', width: '90px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', maxLength: 40, required: true, rule: {
            type: 'str',
            range: [1, 40]
        }},
        // {type: 'img', name: 'icon', title: '专题图标',rule: {
        //     type: 'str',
        //     range: [0, 255]
        // }},
        {type: 'img', name: 'poster', title: '专题海报',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'img', name: 'square', title: '专题方图',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'textarea', name: 'introduction', title: '专题简介',maxLength: 100, rule: {
            type: 'str',
            range: [0, 100]
        }},
    ]
};
//商品管理-专题排期列表
App.util.ns('Admin.Goods.JmTheme');
App.pages.add((function(){
    var NS = Admin.Goods.JmTheme;
    var page = new App.Page({
        name: 'goods/jmtheme/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-crosshairs"></i>',
            content: '商品管理'
        }, {
            content: '专题排期'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/jmtheme',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [1, '在线'],
                    [2, '下线']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.jmtheme.create'},
                {parent: 'view', permission: 'op:admin.goods.jmtheme.detail'},
                {parent: 'edit', permission: 'op:admin.goods.jmtheme.update'},
                {type: 'inline', permission: 'gp:admin/goods/jmtheme', name: '专题区商品',
                    operation: function(dataTable, jmtheme){
                        App.nav.open('goods/jmthemegoods/index', {
                            theme_id: jmtheme.id,
                            jmtheme_name: jmtheme.name
                        });
                    }
                },
                {type: 'inline', permission: 'op:admin.goods.jmtheme.online',
                    name: '上线',
                    operation: {type: 'change', url: 'online'},
                    conditions: [['status', '2']]
                },
                {type: 'inline', permission: 'op:admin.goods.jmtheme.offline',
                    name: '下线',
                    operation: {type: 'change', url: 'offline'},
                    conditions: [['status', '1']]
                },
                {parent: 'drop', permission: 'op:admin.goods.jmtheme.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.jmtheme.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.goods.jmtheme.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            dragSort:{
                permission: 'op:admin.goods.jmtheme.sort',
                url:'sort',
                filed:'sort',
                conditions:[['status', '1']]
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//商品管理-商品即秒排期-配置文件
App.util.ns('Admin.Goods.JmThemeGoods');
Admin.Goods.JmThemeGoods.Conf = {
    columns: [
        {name: '商品', width: '200px', value: function(item){
            return item.goods ? item.goods.name : '未分配';
        }},
        {name: '专题名', width: '120px', value: function(item){
            return item.jmtheme ? item.jmtheme.name : '未分配';
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'selectLists', name: 'goods_id', title: '商品', required: true,
            data_id: 'id',
            data_name: function(item){
                return item.id+':'+item.name;
            },
            dataTable: {
                baseUrl: '/admin/goods/goods',
                dataUrl: 'lists?status=1',
                data_id: 'id',
                data_name: 'name',
                table: {
                    id: 'id',
                    main: 0,
                    columns: [
                        {name: '商品名', value: 'name'}
                    ]
                },
                filter: [
                    {type: 'keywords'}
                ],
                height: '720px'
            }
        }
    ]
};
//商品管理-商品即秒排期列表
App.util.ns('Admin.Goods.JmThemeGoods');
App.pages.add((function(){
    var NS = Admin.Goods.JmThemeGoods;
    var page = new App.Page({
        name: 'goods/jmthemegoods/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/jmthemegoods',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                //{type: 'keywords'},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.jmthemegoods.create'},
                {type: 'globe', permission: 'op:admin.goods.jmthemegoods.multiChangeCategory', name: '批量添加', operation: function(dataTable){
                    var win = dataTable.wins.get('categoryManage');
                    win.setTitle('批量添加商品');
                    win.show();
                    win.dataTable.table.frame.find('.chk-row').prop('checked', false).change();
                    //设置按钮
                    win.setBtns([(function(){
                        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
                        cancelBtn.click(function(){
                            win.hide();
                        });
                        return cancelBtn;
                    })(), (function(){
                        var saveBtn = $('<a class="btn btn-success btn-xs">保存</a>');
                        saveBtn.click(function(){
                            var goodsIds = win.dataTable.table.getSelectedIds();
                            var themeIds = dataTable.param.data.theme_id;
                            if(goodsIds.length){
                                dataTable.postData({
                                    url: 'multiChangeCategory',
                                    alert: '保存成功！',
                                    reload: true,
                                    data: {
                                        theme_ids: themeIds,
                                        goods_ids: goodsIds.join(',')
                                    },
                                    after: function(){
                                        win.hide();
                                    }
                                });
                            }else{
                                App.util.hint.alert({
                                    text: '没有选择商品'
                                });
                            }
                        });
                        return saveBtn;
                    })()]);
                }},
                //{parent: 'view', permission: 'op:admin.goods.jmthemegoods.detail'},
                {parent: 'edit', permission: 'op:admin.goods.jmthemegoods.update'},
                {parent: 'drop', permission: 'op:admin.goods.jmthemegoods.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.jmthemegoods.multiDelete'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            after: function(dataTable){
                //栏目组织
                dataTable.wins.add(new NS.CategoryManage(dataTable), 'categoryManage');
            },
            dragSort:{
                permission: 'op:admin.goods.jmthemegoods.sort',
                url:'sort',
                filed:'sort'
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
    });
    //页面打开
    page.showStack.add('openPage', function(){
        if(this.params){
            var params = this.params;
            //设置面包屑导航
            this.setBreadcrumb([{
                icon: '<i class="fa fa-crosshairs"></i>',
                content: '商品与专题排期'
            }, {
                content: '商品管理',
                action: function(){
                    App.nav.back();
                }
            }, {
                active: true,
                content: '专题商品管理 - ' + params['jmtheme_name']
            }]);
            //设置参数
            for(var i in params){
                this.dataTable.param.set(i, params[i]);
            }
            if(this.dataTable.paginator){
                this.dataTable.paginator.currentPage = 1;
            }
            //加载数据
            this.dataTable.loadData();
        }
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//商品管理-专题排期-专题区商品
App.util.ns('Admin.Goods.JmThemeGoods');
Admin.Goods.JmThemeGoods.CategoryManage = function(dataTable){
    var win = new App.Win({name: 'goods_jmthemeGoods_manage', width: '400px'});
    //列表
    win.dataTable = new App.DataTable({
        baseUrl: '/admin/goods/goods',
        dataUrl: 'newlists',
        table: {
            id: 'id',
            main: 0,
            //showId: false,
            columns: [
                {name: '商品名称', value: function(item){
                    return '/'+(item.goods ? item.goods.name+'/' : '')+item.name;
                }}
            ]
        },
        filter: [
            {type: 'keywords'}
        ],
        floatable: false,
        paginator: false
    });
    win.setContent(win.dataTable.frame);
    win.hide();
    //加载数据
    win.dataTable.loadData();
    return win;
};
//商品管理-分区排期列表-配置文件
App.util.ns('Admin.Goods.JmPartition');
Admin.Goods.JmPartition.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '分区样式', width: '100px',value: function(item){
            switch (item.style+'') {
                case '1':
                    return '4图';
                case '2':
                    return '6图';
                case '3':
                    return '10图';
                case '4':
                    return '单图';
                case '5':
                    return '九宫格';
            }
        }},
        {name: '九宫格样式', width: '100px',value: function(item){
            switch (item.flag+'') {
                case '1':
                    return '左上4图';
                case '2':
                    return '右上4图';
                case '3':
                    return '左下4图';
                case '4':
                    return '右下4图';
            }
        }},
        {name: '分区简介', width: '300px',value: 'introduction'},
        {name: '状态', width: '80px',value: function(item){
            switch (item.status+'') {
                case '1':
                    return '在线';
                case '2':
                    return '下线';
            }
        }},
        {name: '创建日期', width: '90px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', maxLength: 40, required: true, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'imgs', name: 'imgs', title: '九宫格4图',rule: {
            type: 'str'
        }},
        {type: 'chosen', name: 'style', title: '分区样式',
            items: [
                ['1', '4图'],
                ['2', '6图'],
                ['3', '10图'],
                ['4', '单图'],
                ['5', '九宫格']
            ],
            defaults: '0'
        },
        {type: 'chosen', name: 'flag', title: '九宫格样式',
            items: [
                ['1', '左上4图'],
                ['2', '右上4图'],
                ['3', '左下4图'],
                ['4', '右上4图'],
            ],
            defaults: '0'
        },
        {type: 'textarea', name: 'introduction', title: '分区简介',maxLength: 100, rule: {
            type: 'str',
            range: [0, 100]
        }},
    ]
};
//商品管理-分区排期列表
App.util.ns('Admin.Goods.JmPartition');
App.pages.add((function(){
    var NS = Admin.Goods.JmPartition;
    var page = new App.Page({
        name: 'goods/jmpartition/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-crosshairs"></i>',
            content: '商品管理'
        }, {
            content: '分区排期'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/jmpartition',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [1, '在线'],
                    [2, '下线']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.jmpartition.create'},
                {parent: 'view', permission: 'op:admin.goods.jmpartition.detail'},
                {parent: 'edit', permission: 'op:admin.goods.jmpartition.update'},
                {type: 'inline', permission: 'gp:admin/goods/jmpartition', name: '分区商品',
                    operation: function(dataTable, jmpartition){
                        App.nav.open('goods/jmpartitiongoods/index', {
                            partition_id: jmpartition.id,
                            jmpartition_name: jmpartition.name
                        });
                    }
                },
                {type: 'inline', permission: 'op:admin.goods.jmpartition.online',
                    name: '上线',
                    operation: {type: 'change', url: 'online'},
                    conditions: [['status', '2']]
                },
                {type: 'inline', permission: 'op:admin.goods.jmpartition.offline',
                    name: '下线',
                    operation: {type: 'change', url: 'offline'},
                    conditions: [['status', '1']]
                },
                {parent: 'drop', permission: 'op:admin.goods.jmpartition.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.jmpartition.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.goods.jmpartition.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            dragSort:{
                permission: 'op:admin.goods.jmpartition.sort',
                url:'sort',
                filed:'sort',
                conditions:[['status', '1']]
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//商品管理-商品即秒排期-配置文件
App.util.ns('Admin.Goods.JmPartitionGoods');
Admin.Goods.JmPartitionGoods.Conf = {
    columns: [
        {name: '商品', width: '200px', value: function(item){
            return item.goods ? item.goods.name : '未分配';
        }},
        {name: '分区名', width: '120px', value: function(item){
            return item.jmpartition ? item.jmpartition.name : '未分配';
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'selectLists', name: 'goods_id', title: '商品', required: true,
            data_id: 'id',
            data_name: function(item){
                return item.id+':'+item.name;
            },
            dataTable: {
                baseUrl: '/admin/goods/goods',
                dataUrl: 'lists?status=1',
                data_id: 'id',
                data_name: 'name',
                table: {
                    id: 'id',
                    main: 0,
                    columns: [
                        {name: '商品名', value: 'name'}
                    ]
                },
                filter: [
                    {type: 'keywords'}
                ],
                height: '720px'
            }
        }
    ]
};
//商品管理-商品即秒排期列表
App.util.ns('Admin.Goods.JmPartitionGoods');
App.pages.add((function(){
    var NS = Admin.Goods.JmPartitionGoods;
    var page = new App.Page({
        name: 'goods/jmpartitiongoods/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/jmpartitiongoods',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                //{type: 'keywords'},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.jmpartitiongoods.create'},
                {type: 'globe', permission: 'op:admin.goods.jmpartitiongoods', name: '批量添加', operation: function(dataTable){
                    var win = dataTable.wins.get('categoryManage');
                    win.setTitle('批量添加商品');
                    win.show();
                    win.dataTable.table.frame.find('.chk-row').prop('checked', false).change();
                    //设置按钮
                    win.setBtns([(function(){
                        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
                        cancelBtn.click(function(){
                            win.hide();
                        });
                        return cancelBtn;
                    })(), (function(){
                        var saveBtn = $('<a class="btn btn-success btn-xs">保存</a>');
                        saveBtn.click(function(){
                            var goodsIds = win.dataTable.table.getSelectedIds();
                            var partitionIds = dataTable.param.data.partition_id;
                            if(goodsIds.length){
                                dataTable.postData({
                                    url: 'multiChangeCategory',
                                    alert: '保存成功！',
                                    reload: true,
                                    data: {
                                        partition_ids: partitionIds,
                                        goods_ids: goodsIds.join(',')
                                    },
                                    after: function(){
                                        win.hide();
                                    }
                                });
                            }else{
                                App.util.hint.alert({
                                    text: '没有选择商品'
                                });
                            }
                        });
                        return saveBtn;
                    })()]);
                }},
                //{parent: 'view', permission: 'op:admin.goods.jmpartitiongoods.detail'},
                {parent: 'edit', permission: 'op:admin.goods.jmpartitiongoods.update'},
                {parent: 'drop', permission: 'op:admin.goods.jmpartitiongoods.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.jmpartitiongoods.multiDelete'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.CategoryManage(dataTable), 'categoryManage');
            },
            dragSort:{
                permission: 'op:admin.goods.jmpartitiongoods.sort',
                url:'sort',
                filed:'sort'
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
    });
    //页面打开
    page.showStack.add('openPage', function(){
        if(this.params){
            var params = this.params;
            //设置面包屑导航
            this.setBreadcrumb([{
                icon: '<i class="fa fa-crosshairs"></i>',
                content: '商品与分区排期'
            }, {
                content: '商品管理',
                action: function(){
                    App.nav.back();
                }
            }, {
                active: true,
                content: '分区商品管理 - ' + params['jmpartition_name']
            }]);
            //设置参数
            for(var i in params){
                this.dataTable.param.set(i, params[i]);
            }
            if(this.dataTable.paginator){
                this.dataTable.paginator.currentPage = 1;
            }
            //加载数据
            this.dataTable.loadData();
        }
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//商品管理-专题排期-专题区商品
App.util.ns('Admin.Goods.JmPartitionGoods');
Admin.Goods.JmPartitionGoods.CategoryManage = function(dataTable){
    var win = new App.Win({name: 'goods_jmpartitionGoods_manage', width: '400px'});
    //列表
    win.dataTable = new App.DataTable({
        baseUrl: '/admin/goods/goods',
        dataUrl: 'newlists',
        table: {
            id: 'id',
            main: 0,
            //showId: false,
            columns: [
                {name: '商品名称', value: function(item){
                    return '/'+(item.goods ? item.goods.name+'/' : '')+item.name;
                }}
            ]
        },
        filter: [
            {type: 'keywords'}
        ],
        floatable: false,
        paginator: false
    });
    win.setContent(win.dataTable.frame);
    win.hide();
    //加载数据
    win.dataTable.loadData();
    return win;
};
//物流管理-物流列表-配置文件
App.util.ns('Admin.Logistics.Logistics');
Admin.Logistics.Logistics.Conf = {
    columns: [
        {name: '订单名称', value: function(item){
            return item.orders ? ('ID：'+item.orders.id+'-'+item.orders.order_name) : '-- --';
        }},
        // {name: '供应商', width: '150px', value: function(item){
        //     return item.supplier ? item.supplier.name : '-- --';
        // }},
        {name: '用户', width: '150px', value: function(item){
            return item.user ? item.user.nickname : '-- --';
        }},
        {name: '快递公司', width: '100px', value: function(item){
            return item.delivers ? item.delivers.name : '-- --';
        }},
        {name: '快递编码', width: '100px', value: function(item){
            return item.delivers ? item.delivers.code : '-- --';
        }},
        {name: '运单号', width: '100px',value: 'deliver_no'},
        {name: '类型', width: '90px',value: function(item){
            switch (item.type+'') {
                case '0':
                    return '寄出';
                case '1':
                    return '用户寄回';
                case '2':
                    return '再次寄出';
            }
        }},
        {name: '状态', width: '90px',value: function(item){
            switch (item.status+'') {
                case '-1':
                    return '待查询';
                case '0':
                    return '查询异常';
                case '1':
                    return '暂无记录';
                case '2':
                    return '在途中';
                case '3':
                    return '派送中';
                case '4':
                    return '已签收';
                case '5':
                    return '用户拒签';
                case '6':
                    return '疑难件';
                case '7':
                    return '无效单';
                case '8':
                    return '超时单';
                case '9':
                    return '签收失败';
                case '10':
                    return '退回';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'chosen', name: 'order_id', title: '订单名称',
            items: App.models.get('orders-all'),
            item_key: 'id',
            item_name: 'order_name',
            value_key: 'id',
            rule:{
                type: 'num',
                range: [1, 10]
            }
        },
        {type: 'input', name: 'deliver_code', title: '快递编码', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'input', name: 'deliver_no', title: '运单号', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},

        {type: 'textarea', name: 'record_json', title: '物流信息'}
    ]
};
//物流管理-物流列表
App.util.ns('Admin.Logistics.Logistics');
App.pages.add((function(){
    var NS = Admin.Logistics.Logistics;
    var page = new App.Page({
        name: 'logistics/logistics/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-truck"></i>',
            content: '物流管理'
        }, {
            content: '物流列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/logistics/logistics',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: true,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'type', title: '类型', width: '90px', items: [
                    [0, '寄出'],
                    [1, '用户寄回'],
                    [2, '再次寄出']
                ]},
                {type: 'select', name: 'status', title: '订单状态', width: '90px', items: [
                    [-1, '待查询'],
                    [0, '查询异常'],
                    [1, '暂无记录'],
                    [2, '在途中'],
                    [3, '派送中'],
                    [4, '已签收'],
                    [5, '用户拒签'],
                    [6, '疑难件'],
                    [7, '无效单'],
                    [8, '超时单'],
                    [9, '签收失败'],
                    [10, '退回']
                ]},
            ],
            menu: [
                //{parent: 'add', permission: 'op:admin.orders.price.create'},
                {parent: 'view', permission: 'op:admin.orders.price.detail'},
                //{parent: 'edit', permission: 'op:admin.orders.price.update'},
                {parent: 'drop', permission: 'op:admin.orders.price.delete'},
                {parent: 'multiDrop', permission: 'op:admin.orders.price.multiDelete'},
                //{parent: 'oplog', permission: 'op:admin.orders.price.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form),
                    onChange:function (form,data) {
                        var htmlStr = '';
                        var recordJson=data.record_json;
                        if(!recordJson){
                            htmlStr = '暂无物流信息';
                        }
                        if(recordJson){
                            recordJson = JSON.parse(data.record_json);
                            if(recordJson.constructor!== Array){
                                htmlStr = '暂无物流信息';
                            }
                            for (var i =0 ;i<recordJson.length;i++){
                                htmlStr += recordJson[i].time+':'+recordJson[i].context+'<br>';
                            }
                        }
                        form.formItems['record_json'].change(htmlStr);
                    }
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//物流管理-快递列表-配置文件
App.util.ns('Admin.Logistics.Delivers');
Admin.Logistics.Delivers.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '编码', width: '300px',value: 'code'},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'}
    ]
};
//物流管理-快递列表
App.util.ns('Admin.Logistics.Delivers');
App.pages.add((function(){
    var NS = Admin.Logistics.Delivers;
    var page = new App.Page({
        name: 'logistics/delivers/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-truck"></i>',
            content: '物流管理'
        }, {
            content: '快递列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/logistics/delivers',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'drop', permission: 'op:admin.logistics.delivers.delete'},
                {parent: 'multiDrop', permission: 'op:admin.logistics.delivers.multiDelete'},
                //{parent: 'oplog', permission: 'op:admin.logistics.delivers.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//用户管理-用户列表-配置文件
App.util.ns('Admin.User.User');
Admin.User.User.Conf = {
    columns: [
        {name: '昵称', value: 'nickname'},
        {name: '电话', width: '60px',value: 'phone'},
        {name: '性别', width: '60px',value: function(item){
            switch (item.gender+'') {
                    case '0':
                        return '未知';
                    case '1':
                        return '男';
                    case '2':
                        return '女';
            }
        }},
        {name: '企业', width: '100px', value: function(item){
            return item.enterprise ? item.enterprise.name : '-- --';
        }},
        {name: '押金', width: '60px',value: 'deposit'},
        {name: '押金状态', width: '70px', value: function(item){
            switch (item.deposit_status+'') {
                case '0':
                    return '未交';
                case '1':
                    return '已交';
            }
        }},
        {name: '押金订单名', width: '150px', value: function(item){
            return item.orders ? item.orders.order_name : '-- --';
        }},
        {name: '余额', width: '60px',value: 'balance'},
        {name: '积分', width: '60px',value: 'score'},
        {name: '企业福利', width: '80px',value: 'enterprise_fee'},
        {name: '状态', width: '60px',value: function(item){
            switch (item.status+'') {
                case '1':
                    return '正常';
                case '2':
                    return '禁用';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'nickname', title: '昵称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'img', name: 'img', title: '头像',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'input', name: 'address', title: '联系地址', maxLength: 40, rule: {
            type: 'str',
            range: [1, 500]
        }},
        {type: 'input', name: 'phone', title: '电话', required: true, rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'input', name: 'email', title: '邮箱', rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'chosen', name: 'gender', title: '性别', items: [
            ['0', '未知'],
            ['1', '男'],
            ['2', '女']
        ]}
    ]
};
//用户管理-用户列表
App.util.ns('Admin.User.User');
App.pages.add((function(){
    var NS = Admin.User.User;
    var page = new App.Page({
        name: 'user/user/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-user"></i>',
            content: '用户管理'
        }, {
            content: '用户列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/user/user',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'deposit_status', title: '押金状态', width: '80px', items: [
                    [0, '未交'],
                    [1, '已交']
                ]},
                {type: 'select', name: 'status', title: '状态', width: '80px', items: [
                    [1, '正常'],
                    [2, '禁用']
                ]},
                {type: 'select', name: 'enterprise_id', title: '企业', width: '120px',
                    items: App.models.get('enterprise-all'),
                    item_key: 'id',
                    item_name: 'name'
                }
            ],
            menu: [
                //{parent: 'add', permission: 'op:admin.user.user.create'},
                {parent: 'view', permission: 'op:admin.user.user.detail'},
                {parent: 'edit', permission: 'op:admin.user.user.update'},
                {type: 'inline', permission: 'op:admin.user.user.open', name: '开启', operation: {type: 'change', url: 'open'}, conditions: [['status', '2']]},
                {type: 'inline', permission: 'op:admin.user.user.close', name: '禁用', operation: {type: 'change', url: 'close'}, conditions: [['status', '1']]},
                {parent: 'drop', permission: 'op:admin.user.user.delete'},
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.user.user.multiOpen', name: '开启', operation: {type: 'change', url: 'multiOpen', confirm: true}},
                    {type: 'multi', permission: 'op:admin.user.user.multiClose', name: '禁用', operation: {type: 'change', url: 'multiClose', confirm: true}}
                    ], permission:[
                        'op:admin.user.user.multiOpen',
                        'op:admin.user.user.multiClose'
                ]},
                {parent: 'multiDrop', permission: 'op:admin.user.user.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.user.user.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//订单管理-订单列表-配置文件
App.util.ns('Admin.Orders.Orders');
Admin.Orders.Orders.Conf = {
    columns: [
        {name: '订单名称', value: 'order_name'},
        {name: '用户昵称', width: '100px',value: function(item){
            return item.user ? item.user.nickname : '-- --';  
        }},
        // {name: '供应商', width: '150px', value: function(item){
        //         return item.supplier ? item.supplier.name : '-- --';
        // }},
        // {name: '体验记录名', width: '120px', value: function(item){
        //     return item.experience ? item.experience.name : '-- --';
        // }},
        {name: '微信订单号', width: '200px',value: 'wxorder'},
        // {name: '发票状态', width: '80px',value: function(item){
        //     switch (item.invoice_status+'') {
        //         case '0':
        //             return '不需要';
        //         case '1':
        //             return '需要';
        //     }
        // }},
        {name: '总金额', width: '60px',value: 'amount'},
        {name: '订单创建时间', width: '90px', value: function(item){
            return App.util.formator.dateTime(item.start_time).substr(5, 11);
        }},
        {name: '支付完成时间', width: '90px', value: function(item){
            return App.util.formator.dateTime(item.end_time).substr(5, 11);
        }},
        {name: '交易类型', width: '90px',value: function(item){
            switch (item.type+'') {
                case '1':
                    return '充值';
                case '2':
                    return '交押金';
                case '3':
                    return '退押金';
                case '4':
                    return '商城订单支付';
                case '5':
                    return '商城订单退款';
            }
        }},
        {name: '订单状态', width: '80px',value: function(item){
            switch (item.status+'') {
                case '1':
                    return '待支付';
                case '2':
                    return '支付完成';
                case '3':
                    return '订单完成';
                case '4':
                    return '失败';
            }
        }},
        {name: '快递状态', width: '90px',value: function(item){
            switch (item.deliver_status+'') {
                case '0':
                    return '-- --';
                case '1':
                    return '填充完毕';
                case '2':
                    return '订单已签收';
            }
        }},
        {name: '时间', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'order_name', title: '订单名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        // {type: 'chosen', name: 'supplier_id', title: '供应商',
        //     items: App.models.get('supplier-all'),
        //     item_key: 'id',
        //     item_name: 'name',
        //     value_key: 'id',
        //     rule:{
        //         type: 'num',
        //         range: [1, 10]
        //     }
        // },
        {type: 'input', name: 'message', title: '备注', maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'static', name: 'amount', title: '总金额'},
        {type: 'static', name: 'step_fee', title: '运动优惠金额'},
        {type: 'static', name: 'enterprise_fee', title: '企业福利抵减'},
        {type: 'static', name: 'total', title: '总件数'},
        {type: 'textarea', name: 'order_info', title: '订单详细信息'},
        {type: 'textarea', name: 'consignee_info', title: '收货人地址'},
        // {type: 'textarea', name: 'invoice_info', title: '发票信息'},
        // {type: 'chosen', name: 'invoice_status', title: '是否开发票', items: [
        //     ['0', '不需要'],
        //     ['1', '需要']
        // ]},
        {type: 'chosen', name: 'status', title: '订单状态', items: [
            ['1', '待支付'],
            ['2', '支付完成'],
            ['3', '支付完成'],
            ['4', '失败']
        ]},
        {type: 'chosen', name: 'deliver_id', title: '快递名称',
            items: App.models.get('delivers-all'),
            item_key: 'id',
            item_name: 'name',
            value_key: 'id',
            rule:{
                type: 'num',
                range: [1, 10]
            }
        },
        {type: 'input', name: 'deliver_no', title: '快递运单号'}
    ]
};
//订单管理--订单列表
App.util.ns('Admin.Orders.Orders');
App.pages.add((function(){
    var NS = Admin.Orders.Orders;
    var page = new App.Page({
        name: 'orders/orders/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-dollar"></i>',
            content: '订单管理'
        }, {
            content: '订单列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/orders/orders',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: true,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                // {type: 'select', name: 'invoice_status', title: '发票状态', width: '100px', items: [
                //     [0, '不需要'],
                //     [1, '需要']
                // ]},
                {type: 'select', name: 'type', title: '交易类型', width: '100px', items: [
                    [1, '充值'],
                    [2, '交押金'],
                    [3, '退押金'],
                    [4, '商城订单支付'],
                    [5, '商城订单退款']
                ]},
                {type: 'select', name: 'status', title: '订单状态', width: '90px', items: [
                    [1, '待支付'],
                    [2, '支付完成'],
                    [3, '订单完成'],
                    [4, '失败'],
                ]},
                {type: 'select', name: 'deliver_status', title: '快递状态', width: '90px', items: [
                    [0, '-- --'],
                    [1, '填充完毕'],
                    [2, '订单已签收']
                ]}
            ],
            menu: [
                //{parent: 'add', permission: 'op:admin.orders.orders.create'},
                {parent: 'view', permission: 'op:admin.orders.orders.detail'},
                //{parent: 'edit', permission: 'op:admin.orders.orders.update'},
                {
                    type: 'inline',
                    name: '运单填写',
                    permission: 'gp:admin/orders/orders',
                    conditions: [['type', '4']],
                    operation: function(dataTable, orders){
                        var win = dataTable.wins.get('deliversno');
                        win.setTitle('运单填写 - '+orders.order_name);
                        win.form.change({
                            order_id: orders.id,
                            user_id: orders.user_id,
                            deliver_no:orders.deliver_no,
                            deliver_code:orders.deliver_code
                        });
                        if(orders.deliver){
                            win.form.formItems['deliver_code'].change(orders.deliver.id, orders.deliver.name, orders.deliver);
                        }else{
                            win.form.formItems['deliver_code'].reset();
                        }
                        win.show();
                    }
                },
                {parent: 'drop', permission: 'op:admin.orders.orders.delete'},
                {parent: 'multiDrop', permission: 'op:admin.orders.orders.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.orders.orders.getOpLogs'},
                {type: 'inline', permission: 'op:admin.orders.orders.complete',
                    name: '订单完成', operation: {type: 'change', url: 'complete'},
                    conditions: [['status', '2'],['type', '4']]
                }
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form),
                    onChange: function(form, data){
                        var htmlinfo = '';
                        var htmljson = '';
                        var order_info=data.order_info;
                        var consignee_info=data.consignee_info;
                        if(!order_info){
                            htmlinfo = '暂无信息';
                        }else{
                            order_info = JSON.parse(order_info);
                            if(order_info.constructor!== Array){
                                htmlinfo = '暂无信息';
                            }
                            for (var i =0 ;i<order_info.length;i++){
                                htmlinfo += '商品名称：'+order_info[i].name;
                                if(order_info[i].specStr){
                                    htmlinfo += '，规格：'+order_info[i].specStr;
                                }else{
                                    htmlinfo += '，规格：默认';
                                }
                                htmlinfo += '，数量：'+ order_info[i].num+
                                '，价格：'+order_info[i].price;
                                htmlinfo += '<br>';
                            }
                        }
                        if(!consignee_info){
                            htmljson = '暂无信息';
                        }else{
                            consignee_info = JSON.parse(consignee_info);
                            htmljson += '收货地址：'+consignee_info.cityName+consignee_info.countyName+consignee_info.detailInfo+'<br>';
                            htmljson += '手机号：'+consignee_info.telNumber+'<br>';
                            htmljson += '昵称：'+consignee_info.userName;
                        }
                        form.formItems['order_info'].change(htmlinfo);
                        form.formItems['consignee_info'].change(htmljson);

                        // if(data.type+'' === '7'){
                        //     var orderInfo = data.orderInfoText;
                        //     var consigneeInfo = JSON.parse(data.consignee_info);
                        //     var orderInfoText = '';
                        //     for(var i in orderInfo){
                        //         var goodsName = orderInfo[i].goodsName;
                        //         var goodsNum = orderInfo[i].num;
                        //         var goodsPrice = orderInfo[i].price;
                        //         orderInfoText += goodsName +' '+ goodsNum + ' 件 ' + goodsPrice + '元<br>';
                        //     }
                        //     var userName = consigneeInfo.userName;
                        //     var telNumber = consigneeInfo.telNumber;
                        //     var userddress = consigneeInfo.provinceName + consigneeInfo.cityName + consigneeInfo.countyName + consigneeInfo.detailInfo;
                        //     var consigneeInfoText = userName + "<br>" + telNumber + "<br>" + userddress;
                        //     form.formItems['order_details'].change(orderInfoText ? orderInfoText : '');
                        //     form.formItems['consignee_details'].change(consigneeInfoText ? consigneeInfoText : '');
                        // }
                    }
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.Deliversno(dataTable), 'deliversno');
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//订单管理-运单填写
App.util.ns('Admin.Orders.Orders');
Admin.Orders.Orders.Deliversno = function(dataTable){
    var win = new App.Win({
        name: 'deliversno',
        title: '运单填写',
        width: '720px'
    });

    //表单提交
    var form = new App.Form({
        items: [
            {type: 'hidden', name: 'order_id'},
            {type: 'hidden', name: 'user_id'},
            {type: 'selectLists', name: 'deliver_code', title: '快递字母简称', required: true,
                data_id: 'id', 
                data_name: function(item){
                    return item.code+':'+item.name;
                },
                dataTable: {
                    baseUrl: '/admin/logistics/delivers',
                    dataUrl: 'lists',
                    data_id: 'id',
                    data_name: 'name',
                    table: {
                        id: 'id',
                        main: 0,
                        columns: (function(){
                            return App.util.copy(Admin.Logistics.Delivers.Conf.columns);
                        })()
                    },
                    filter: [
                        {type: 'keywords'},
                        {type: 'timeRange'}
                    ],
                    height: '720px'
                }
            },
            {type: 'input', name: 'deliver_no', title: '快递单号', required: true, rule: {
                type: 'str',
                range: [6, 100]
            }}
        ],
        onChange: function(form, data){
            form.formItems['deliver_code'].change(data.deliver_code?data.deliver_code:'');
        }
    });
    form.fix(win.contentContainer);
    win.form = form;
    win.changeOrders = function(orders){
        win.orders = orders;
        return win;
    };
    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">提交</a>');
        saveBtn.click(function(){
            var formData = form.getData();
            App.util.request.postData({
                url: '/admin/orders/orders/createlogistics',
                data: {
                    order_id: formData['order_id'],
                    user_id: formData['user_id'],
                    deliver_code: formData['deliver_code'],
                    deliver_no: formData['deliver_no']
                },
                loading: new App.Loading(win.contentContainer),
                success: function(){
                    App.util.hint.toast({
                        type: 'ok',
                        text: '提交成功'
                    }).delay(500, function(){
                        win.hide();
                    });
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};
//订单管理-商城订单列表-配置文件
App.util.ns('Admin.Orders.Shopping');
Admin.Orders.Shopping.Conf = {
    columns: [
        {name: '昵称', value: function(item){
            return item.user ? item.user.nickname : '-- --';
        }},
        {name: '订单号',width: '200px', value: 'wxorder'},
        // {name: '供应商',width: '150px', value: function(item){
        //     return item.supplier ? item.supplier.name : '暂无';
        // }},
        {name: '备注',width: '90px', value: function(item){
            return item.message ? item.message : '暂无';
        }},
        {name: '商品信息', width: '240px', value: function(item){
            var returnStr = '';
            for(var i=0;i<item.order_info.length;i++){
                var index = item.order_info[i];
                if(index.specStr){
                    returnStr = [returnStr +'名称：'+index.name+'，规格：'+index.specStr+'，价格：'+index.price+'，数量：'+index.num +'<br>'];
                }else{
                    returnStr = [returnStr +'名称：'+index.name+'，规格：默认 ，价格：'+index.price+'，数量：'+index.num +'<br>'];
                }
            }
            returnStr = [returnStr + '运动优惠金额：'+item.step_fee+'元<br>'];
                returnStr = [returnStr + '企业福利抵减：'+item.enterprise_fee+'元'];
            return returnStr;
        }},
        {name: '收货人信息', width: '200px', value: function(item){
            var returnStr = '';
            var index = item.consignee_info;
            var address = '';
            if(index.provinceName){
                address += index.provinceName;
            }
            if(index.cityName){
                address += index.cityName;
            }
            if(index.countyName){
                address += index.countyName;
            }
            if(index.detailInfo){
                address += index.detailInfo;
            }

            if(index.userName){
                returnStr = [returnStr +'收件人姓名：'+index.userName+'<br> 电话：'+index.telNumber+'<br> 地址：'+address];
            }else{
                returnStr = [returnStr +'暂无信息'];
            }
            return returnStr;
        }},
        {name: '运单信息', width: '150px', value: function(item){
            return item.delivers ? ['物流公司：'+item.delivers.name,'<br>','运单号：'+item.deliver_no ]: '-- --';
        }},
        {name: '订单创建时间', width: '90px', value: function(item){
            return App.util.formator.dateTime(item.start_time).substr(5, 11);
        }},
        {name: '订单状态', width: '80px', value: function(item){
            switch (item.status+'') {
                case '1':
                    return '待支付';
                case '2':
                    return '支付完成';
                case '3':
                    return '订单完成';
                case '4':
                    return '失败';
            }
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},

    ]
};
//订单管理-商城订单列表
App.util.ns('Admin.Orders.Shopping');
App.pages.add((function(){
    var NS = Admin.Orders.Shopping;
    var page = new App.Page({
        name: 'orders/shopping/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-dollar"></i>',
            content: '订单管理'
        }, {
            content: '商城订单'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/orders/shopping',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '订单状态', width: '80px', items: [
                    [1, '待支付'],
                    [2, '支付完成'],
                    [3, '订单完成'],
                    [4, '失败']
                ]},
                // {type: 'select', name: 'supplier_id', title: '供应商', width: '120px',
                //     items: App.models.get('supplier-all'),
                //     item_key: 'id',
                //     item_name: 'name'
                // }
            ],
            menu: [
                {
                    type: 'inline',
                    name: '运单填写',
                    icon: '<i class="fa fa-server"></i>',
                    floatable: true,
                    permission: 'gp:admin/orders/shopping',
                    conditions: [['type', '4'],['status', '2']],
                    operation: function(dataTable, orders){
                        var win = dataTable.wins.get('deliversno');
                        win.form.change({
                            order_id: orders.id,
                            user_id: orders.user_id,
                        });
                        win.show();
                    }
                },
                {type: 'globe', name: '导出', permission: 'op:admin.orders.shopping.multiExport', operation:function (dataTable) {
                    //发请求ajax
                    $.ajax({
                        url: 'admin/orders/shopping/multiExport',
                        data: dataTable.filter.data,
                        type: "get",
                        async: false,
                        success: function (returnData) {
                            returnData = JSON.parse(returnData)
                            if(returnData.status == '0'){
                                var $a = $("<a>");
                                $a.attr("href", returnData.data.file);
                                $a.attr("download", returnData.data.filename);
                                $("body").append($a);
                                $a[0].click();
                                $a.remove();
                            }else {
                                App.util.hint.toast({
                                    type: 'error',
                                    text: returnData.msg
                                }).delay(500);
                            }
                        },
                        error: function () {
                            App.util.hint.toast({
                                type: 'error',
                                text: '格式不对'
                            }).delay(500);
                        }
                    });

                }},
                {parent: 'multiDrop', permission: 'op:admin.orders.shopping.multiDelete'},
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.Deliversno(dataTable), 'deliversno');
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//订单管理-订单售后-运单填写
App.util.ns('Admin.Orders.Shopping');
Admin.Orders.Shopping.Deliversno = function(dataTable){
    var win = new App.Win({
        name: 'deliversno',
        title: '运单填写',
        width: '720px'
    });

    //表单提交
    var form = new App.Form({
        items: [
            {type: 'hidden', name: 'order_id'},
            {type: 'hidden', name: 'user_id'},
            {type: 'selectLists', name: 'deliver_id', title: '快递字母简称', required: true,
                data_id: 'id', 
                data_name: function(item){
                    return item.code+':'+item.name;
                },
                dataTable: {
                    baseUrl: '/admin/logistics/delivers',
                    dataUrl: 'lists',
                    data_id: 'id',
                    data_name: 'name',
                    table: {
                        id: 'id',
                        main: 0,
                        columns: (function(){
                            return App.util.copy(Admin.Logistics.Delivers.Conf.columns);
                        })()
                    },
                    filter: [
                        {type: 'keywords'},
                        {type: 'timeRange'}
                    ],
                    height: '720px'
                }
            },
            {type: 'input', name: 'deliver_no', title: '快递单号', required: true, rule: {
                type: 'str',
                range: [6, 100]
            }}
        ]
    });
    form.fix(win.contentContainer);
    win.form = form;
    win.changeOrders = function(orders){
        win.orders = orders;
        return win;
    };

    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">提交</a>');
        saveBtn.click(function(){
            var formData = form.getData();
            console.log(formData);
            App.util.request.postData({
                url: '/admin/orders/shopping/createlogistics',
                data: {
                    order_id: formData['order_id'],
                    deliver_id: formData['deliver_id'],
                    deliver_no: formData['deliver_no'],
                    user_id: formData['user_id']
                },
                loading: new App.Loading(win.contentContainer),
                success: function(){
                    App.util.hint.toast({
                        type: 'ok',
                        text: '提交成功'
                    }).delay(500, function(){
                        win.hide();
                    });
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};
//订单管理-订单售后列表-配置文件
App.util.ns('Admin.Orders.AfterSale');
Admin.Orders.AfterSale.Conf = {
    columns: [
        {name: '订单名称', value: function(item){
            return item.orders ? item.orders.order_name : '-- --';
        }},
        // {name: '供应商', width: '150px', value: function(item){
        //     return item.supplier ? item.supplier.name : '-- --';
        // }},
        {name: '用户', width: '100px', value: function(item){
            return item.user ? item.user.nickname : '-- --';
        }},
        {name: '退货金额', width: '100px', value: 'account'},
        {name: '类型', width: '80px', value: function(item){
            switch (item.type+'') {
                case '1':
                    return '换货';
                case '2':
                    return '退货';
                case '3':
                    return '维修';
            }
        }},
        {name: '退款状态', width: '80px', value: function(item){
            switch (item.state+'') {
                case '0':
                    return '未退款';
                case '1':
                    return '已退款';
            }
        }},
        {name: '审核状态', width: '80px', value: function(item){
            switch (item.status+'') {
                case '0':
                    return '申请';
                case '1':
                    return '审核通过';
                case '2':
                    return '审核驳回';
            }
        }},
        {name: '时间', width: '90px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'imgs', name: 'imgs', title: '照片集合', rule: {
            type: 'str',
            range: [0, 1000]
        }},
        {type: 'textarea', name: 'reason', title: '退货理由', maxLength: 1000,
            rule: {
            type: 'str',
            range: [0, 1000]
        }},
        {type: 'textarea', name: 'feedback_msg', title: '反馈信息', maxLength: 1000,
            rule: {
            type: 'str',
            range: [0, 1000]
        }}
    ]
};
//订单管理-订单售后列表
App.util.ns('Admin.Orders.AfterSale');
App.pages.add((function(){
    var NS = Admin.Orders.AfterSale;
    var page = new App.Page({
        name: 'orders/aftersale/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-dollar"></i>',
            content: '订单管理'
        }, {
            content: '订单售后'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/orders/aftersale',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                //{type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'type', title: '类型', width: '80px', items: [
                    [1, '换货'],
                    [2, '退货'],
                    [3, '维修']
                ]},
                {type: 'select', name: 'state', title: '退款状态', width: '80px', items: [
                    [0, '未退款'],
                    [1, '已退款']
                ]},
                {type: 'select', name: 'status', title: '审核状态', width: '80px', items: [
                    [0, '申请'],
                    [1, '审核通过'],
                    [2, '审核驳回']
                ]}
            ],
            menu: [
                {parent: 'view', permission: 'op:admin.orders.aftersale.detail'},
                {type: 'inline', permission: 'op:admin.orders.aftersale.wxrefund', name: '退款',
                    operation: {type: 'change', url: 'wxrefund'},
                    conditions: [['status', '1'],['state', '0'],['type', '2']],
                },
                //{parent: 'edit', permission: 'op:admin.experience.experience.update'},
                {
                    type: 'inline',
                    name: '换货运单',
                    permission: 'gp:admin/orders/aftersale',
                    conditions: [['type', '1'],['status', '1']],
                    operation: function(dataTable, aftersale){
                        var win = dataTable.wins.get('deliversno');
                        win.form.change({
                            order_id: aftersale.order_id,
                        });
                        win.show();
                    }
                },
                {parent: 'drop', permission: 'op:admin.orders.aftersale.delete'},
                {type: 'inline', permission: 'op:admin.orders.aftersale.adopt', name: '通过', operation: {type: 'change', url: 'adopt'}, conditions: [['status', '0']]},
                {type: 'inline', permission: 'op:admin.orders.aftersale.reject', name: '驳回', operation: {type: 'change', url: 'reject'}, conditions: [['status', '0']]},
                {parent: 'multiDrop', permission: 'op:admin.orders.aftersale.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.orders.aftersale.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.Deliversno(dataTable), 'deliversno');
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//订单管理-订单售后-运单填写
App.util.ns('Admin.Orders.AfterSale');
Admin.Orders.AfterSale.Deliversno = function(dataTable){
    var win = new App.Win({
        name: 'deliversno',
        title: '换货运单',
        width: '720px'
    });

    //表单提交
    var form = new App.Form({
        items: [
            {type: 'hidden', name: 'order_id'},
            {type: 'selectLists', name: 'deliver_code', title: '快递字母简称', required: true,
                data_id: 'id', 
                data_name: function(item){
                    return item.code+':'+item.name;
                },
                dataTable: {
                    baseUrl: '/admin/logistics/delivers',
                    dataUrl: 'lists',
                    data_id: 'id',
                    data_name: 'name',
                    table: {
                        id: 'id',
                        main: 0,
                        columns: (function(){
                            return App.util.copy(Admin.Logistics.Delivers.Conf.columns);
                        })()
                    },
                    filter: [
                        {type: 'keywords'},
                        {type: 'timeRange'}
                    ],
                    height: '720px'
                }
            },
            {type: 'input', name: 'deliver_no', title: '快递单号', required: true, rule: {
                type: 'str',
                range: [6, 100]
            }}
        ]
    });
    form.fix(win.contentContainer);
    win.form = form;
    win.changeAftersale = function(aftersale){
        win.aftersale = aftersale;
        return win;
    };

    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">提交</a>');
        saveBtn.click(function(){
            var formData = form.getData();
            App.util.request.postData({
                url: '/admin/orders/aftersale/createlogistics',
                data: {
                    order_id: formData['order_id'],
                    deliver_code: formData['deliver_code'],
                    deliver_no: formData['deliver_no']
                },
                loading: new App.Loading(win.contentContainer),
                success: function(){
                    App.util.hint.toast({
                        type: 'ok',
                        text: '提交成功'
                    }).delay(500, function(){
                        win.hide();
                    });
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};
//财务管理-定价列表-配置文件
App.util.ns('Admin.Finance.Price');
Admin.Finance.Price.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'admin-finance-price-time', name: 'price', required: true, title: '定价'},
        {type: 'textarea', name: 'introduction', title: '说明', maxLength: 200,
            rule: {
            type: 'str',
            range: [0, 200]
        }}
    ]
};
//财务管理-定价
App.util.ns('Admin.Finance.Price.Form');
Admin.Finance.Price.Form.Timeprice = function(config){
    this.config = config;
    this.name = this.config.name;
    this.form = null;
    this.frame = null;
    this.items = [];
    this.mainItem = null;
    //初始化
    this.init();
};
Admin.Finance.Price.Form.Timeprice.prototype = {
    constructor: Admin.Finance.Price.Form.Timeprice,
    init: function(){
        var self = this;
        this.frame = $([
            '<div class="program-epg-container">',
            '   <div class="item main">',
            '       <div class="input-group" style="width:100%">',
            '           <input type="text" class="form-control begin-time" placeholder="开始时间">',
            '           <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            '           <input type="text" class="form-control end-time" placeholder="结束时间">',
            '           <span class="input-group-addon" style="border-left: none;border-right: none;">></span>',
            '           <input type="text" class="form-control unit" placeholder="计费单位">',
            '           <span class="input-group-addon" style="border-left: none;border-right: none;">:</span>',
            '           <input type="text" class="form-control price" placeholder="单位价格">',
            '           <span class="input-group-btn">',
            '               <button class="btn btn-default btn-sm btn-add" type="button" style="border-radius: 0;"><i class="fa fa-plus"></i></button>',
            '           </span>',
            '       </div>',
            '       <span class="form-static" style="display: none;"></span>',
            '   </div>',
            '</div>'
        ].join(''));
        this.frame.find('.begin-time').css({float: 'left', width: '90px', height: '30px'});
        this.frame.find('.input-group-addon').css({float: 'left', width: '30px', height: '30px'});
        this.frame.find('.end-time').css({float: 'left', width: '90px', height: '30px'});
        this.frame.find('.unit').css({float: 'left', width: '90px', height: '30px'});
        this.frame.find('.price').css({float: 'left', width: 'calc(100% - 390px)', height: '30px'});
        this.frame.find('.input-group-btn').css({float: 'left'});
        this.frame.find('.btn-add').click(function(){
            self.getItem().appendTo(self.frame);
        });
        return this;
    },
    setForm: function(form){
        this.form = form;
    },
    getItem: function(){
        this.itemCount += 1;
        var self = this;
        var item = $([
            '<div class="item">',
            '    <div class="input-group" style="width:100%">',
            '        <input type="text" class="form-control begin-time" placeholder="开始时间">',
            '        <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            '        <input type="text" class="form-control end-time" placeholder="结束时间">',
            '        <span class="input-group-addon" style="border-left: none;border-right: none;">></span>',
            '        <input type="text" class="form-control unit" placeholder="计费单位">',
            '        <span class="input-group-addon" style="border-left: none;border-right: none;">:</span>',
            '        <input type="text" class="form-control price" placeholder="单位价格">',
            '        <span class="input-group-btn">',
            '            <button class="btn btn-default btn-sm btn-drop" type="button" style="border-radius: 0;"><i class="fa fa-times"></i></button>',
            '        </span>',
            '    </div>',
            '    <span class="form-static" style="display: none;"></span>',
            '</div>'
        ].join(''));
        item.find('.begin-time').css({float: 'left', width: '90px', height: '30px'});
        item.find('.input-group-addon').css({float: 'left', width: '30px', height: '30px'});
        item.find('.end-time').css({float: 'left', width: '90px', height: '30px'});
        item.find('.unit').css({float: 'left', width: '90px', height: '30px'});
        item.find('.price').css({float: 'left', width: 'calc(100% - 390px)', height: '30px'});
        item.find('.input-group-btn').css({float: 'left'});
        item.find('.btn-drop').click(function(){
            item.remove();
        });
        return item;
    },
    change: function(val){//改变
        this.reset();
        val = JSON.parse(val) ? JSON.parse(val) : '';
        for(var i in val){
            var item = val[i];
            var price = item['price'] ? item['price'] : '';
            var beginTime = item['beginTime'] ?item['beginTime'] : '';
            var endTime = item['endTime'] ? item['endTime'] : '';
            var unit = item['unit'] ? item['unit'] : '';
            if(i+'' === '0'){
                this.frame.find('.item.main .price').val(price);
                this.frame.find('.item.main .begin-time').val(beginTime);
                this.frame.find('.item.main .end-time').val(endTime);
                this.frame.find('.item.main .unit').val(unit);
            }else{
                var itemObj = this.getItem();
                itemObj.find('.price').val(price);
                itemObj.find('.begin-time').val(beginTime);
                itemObj.find('.end-time').val(endTime);
                itemObj.find('.unit').val(unit);
                itemObj.appendTo(this.frame);
            }
        }
        return this;
    },
    view: function(){//查看
        this.flushView();
        this.frame.find('.item > .input-group').hide();
        this.frame.find('.item > .form-static').show();
        return this;
    },
    flushView: function(){
        this.frame.find('.item').each(function(){
            var text = '从第 <span style="color: blue;">'+$(this).find('.begin-time').val() + '</span> 分到第 <span style="color: blue;">' + $(this).find('.end-time').val()+'</span> 分，每 <span style="color: blue;">'+$(this).find('.unit').val()+'</span> 分 <span style="color: red;">';
            text += $(this).find('.price').val()+'</span> 元';
            $(this).find('.form-static').html('<span style="font-size: 13px;">'+text+'</span>');
        });
    },
    reset: function(){
        this.frame.find('.item').each(function(){
            if(!$(this).hasClass('main')){
                $(this).remove();
            }
        });
        this.frame.find('.item.main').find('select').val('').change();
        this.frame.find('.item.main').find('input').val('').change();
        this.frame.find('.item > .input-group').show();
        this.frame.find('.item > .form-static').hide();
        return this;
    },
    edit: function(){
        this.frame.find('.item > .input-group').show();
        this.frame.find('.item > .form-static').hide();
        return this;
    },
    value: function(){
        var self = this;
        var data = [];
        this.frame.find('.item').each(function(){
            var price = $(this).find('.price').val();
            var beginTime = $(this).find('.begin-time').val();
            var endTime = $(this).find('.end-time').val();
            var unit = $(this).find('.unit').val();
            data.push({
                price: price,
                beginTime: beginTime,
                endTime: endTime,
                unit: unit
            });
        });
        return JSON.stringify(data);
    }, 
    enable: function(){
        this.frame.find('select').prop('disabled', false);
        this.frame.find('input').prop('disabled', false);
        return this;
    },
    disable: function(){
        this.frame.find('select').prop('disabled', true);
        this.frame.find('input').prop('disabled', true);
        return this;
    },
    validate: function(){
        var rs = true;
//        this.frame.find('.input-group').each(function(){
//            var epgId = $(this).find('select').val();
//            var times = $(this).find('input').val();
//            if((epgId.length < 1) && (times.length > 1)){
//                $(this).find('select').addClass('error').one('change', function(){
//                    $(this).removeClass('error');
//                });
//                rs = false;
//            }else if((epgId.length > 1) && (times.length < 1)){
//                $(this).find('input').addClass('error').one('change', function(){
//                    $(this).removeClass('error');
//                });
//                rs = false;
//            }
//        });
        return rs; 
    },
    onChange: function(){
        if(this.config.onChange){
            this.config.onChange(this);
        }
    },
    destroy: function(){
        this.frame.remove();
    }
};
//添加到库
App.Form.lib['admin-finance-price-time'] = Admin.Finance.Price.Form.Timeprice;
//财务管理-定价列表
App.util.ns('Admin.Finance.Price');
App.pages.add((function(){
    var NS = Admin.Finance.Price;
    var page = new App.Page({
        name: 'finance/price/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-rmb"></i>',
            content: '财务管理'
        }, {
            content: '定价列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/finance/price',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.finance.price.create'},
                {parent: 'view', permission: 'op:admin.finance.price.detail'},
                {parent: 'edit', permission: 'op:admin.finance.price.update'},
                {parent: 'drop', permission: 'op:admin.finance.price.delete'},
                {parent: 'multiDrop', permission: 'op:admin.finance.price.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.finance.price.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//财务管理-发票列表-配置文件
App.util.ns('Admin.Finance.Invoice');
Admin.Finance.Invoice.Conf = {
    columns: [
        {name: '发票名称', value: 'payer_name'},
        {name: '用户昵称',width: '120px', value: function(item){
            return item.user ? item.user.nickname : '-- --';
        }},
        {name: '收款方姓名', width: '120px', value: 'income_name'},
        {name: '总费用', width: '120px', value: 'fee'},
        {name: '类型', width: '90px',value: function(item){
            switch (item.type+'') {
                case '1':
                    return '个人';
                case '2':
                    return '公司';
            }
        }},
        {name: '状态', width: '90px',value: function(item){
            switch (item.status+'') {
                case '0':
                    return '发票';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'payer_name', title: '发票名称', required: true,},
        {type: 'chosen', name: 'user_id', title: '昵称',required: true,
            items: App.models.get('user-all'),
            item_key: 'id',
            item_name: 'nickname',
            value_key: 'id',
            rule:{
                type: 'num',
                range: [1, 10]
            }
        },
        {type: 'input', name: 'income_name', title: '收款方姓名', required: true,},
        {type: 'img', name: 'img', title: '电子发票',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'textarea', name: 'content', title: '发票信息', maxLength: 1000,
            rule: {
            type: 'str',
            range: [0, 1000]
        }},
    ]
};
//财务管理-发票列表
App.util.ns('Admin.Finance.Invoice');
App.pages.add((function(){
    var NS = Admin.Finance.Invoice;
    var page = new App.Page({
        name: 'finance/invoice/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-rmb"></i>',
            content: '财务管理'
        }, {
            content: '发票列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/finance/invoice',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'type', title: '类型', width: '90px', items: [
                    [1, '个人'],
                    [2, '公司']
                ]},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [0, '发票']
                ]}
            ],
            menu: [
                //{parent: 'add', permission: 'op:admin.finance.price.create'},
                {parent: 'view', permission: 'op:admin.finance.price.detail'},
                //{parent: 'edit', permission: 'op:admin.finance.price.update'},
                {parent: 'drop', permission: 'op:admin.finance.price.delete'},
                {parent: 'multiDrop', permission: 'op:admin.finance.price.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.finance.price.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//报修管理-报修申请
App.util.ns('Admin.Apply.Repair');
App.pages.add((function(){
    var NS = Admin.Apply.Repair;
    var page = new App.Page({
        name: 'apply/repair/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-wrench"></i>',
            content: '报修管理'
        }, {
            content: '报修申请'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/apply/repair',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: [
                    {name: '标题', value: 'title'},
                    {name: '用户', width: '100px', value: function(item){
                        return item.user ? item.user.nickname : '-- --';
                    }},
                    {name: '店面', width: '150px', value: function(item){
                        return item.storefront ? item.storefront.name : '-- --';
                    }},
                    {name: '货柜', width: '150px', value: function(item){
                        return item.cabinet ? item.cabinet.name : '-- --';
                    }},
                    {name: '格子', width: '120px', value: function(item){
                        if(item.cell){
                            return '第 '+item.cell.row + ' 行，第' + item.cell.col + ' 列';
                        }
                        return '-- --';
                    }},
                    {name: '商品', width: '150px', value: function(item){
                        return item.goods ? item.goods.name : '-- --';
                    }},
                    {name: '类型', width: '80px',value: function(item){
                        switch (item.type+'') {
                            case '1':
                                return '柜子问题';
                            case '2':
                                return '仪器问题';
                            case '3':
                                return '其他';
                        }
                    }},
                    {name: '状态', width: '80px',value: function(item){
                        switch (item.status+'') {
                            case '0':
                                return '待处理';
                            case '1':
                                return '已确认';
                            case '2':
                                return '已处理';
                        }
                    }},
                    {name: '创建日期', width: '80px', value: function(item){
                        return App.util.formator.date(item.created_at);
                    }}
                ]
            },
            filter: [
                //{type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'type', title: '类型', width: '90px', items: [
                    [1, '柜子问题'],
                    [2, '仪器问题'],
                    [3, '其他']
                ]},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [0, '待处理'],
                    [1, '已确认'],
                    [2, '已处理']
                ]}
            ],
            menu: [
                {parent: 'view', permission: 'op:admin.apply.repair.detail'},
                {parent: 'edit', permission: 'op:admin.apply.repair.update'},
                {type: 'inline', permission: 'op:admin.apply.repair.finish', name: '已确认', operation: {type: 'change', url: 'finish'}, conditions: [['status', '0']]},
                {type: 'inline', permission: 'op:admin.apply.repair.finied', name: '已处理', operation: {type: 'change', url: 'finied'}, conditions: [['status', '1']]},
                {parent: 'drop', permission: 'op:admin.apply.repair.delete'},
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.user.user.multiFinish', name: '已确认', operation: {type: 'change', url: 'multiFinish', confirm: true}},
                    {type: 'multi', permission: 'op:admin.user.user.multiFinied', name: '已处理', operation: {type: 'change', url: 'multiFinied', confirm: true}}
                ], permission:[
                    'op:admin.user.user.multiFinish',
                    'op:admin.user.user.multiFinied'
                ]},
                {parent: 'multiDrop', permission: 'op:admin.apply.repair.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.apply.repair.getOpLogs'}
            ],
            detail: {
                form: {
                    items: [
                        {type: 'hidden', name: 'id'},
                        {type: 'hidden', name: 'user_id'},
                        {type: 'hidden', name: 'storefront_id'},
                        {type: 'hidden', name: 'cabinet_id'},
                        {type: 'hidden', name: 'cell_id'},
                        {type: 'static', name: 'user_name', title: '用户名称', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'static', name: 'storefront_name', title: '店面名称', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'static', name: 'cabinet_name', title: '货柜名称', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'static', name: 'cell_name', title: '格子位置', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'static', name: 'goods_name', title: '商品名称', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'radio', name: 'type', title: '报修类型', required: true, 
                            items: [
                                [1, '柜子问题'],
                                [2, '仪器问题'],
                                [3, '其他']
                            ],
                            defaults: '2',
                            rule: {
                                type: 'in',
                                in: ['1', '2', '3']
                            }
                        },
                        {type: 'textarea', name: 'introduction', title: '补充说明', maxLength: 200, rule: {
                            type: 'str',
                            range: [0, 200]
                        }}
                    ],
                    onChange: function(self, item){
                        var userName = item.user ? item.user.nickname : '-- --';
                        var storefrontName = item.storefront ? item.storefront.name : '-- --';
                        var cabinetName = item.cabinet ? item.cabinet.name : '-- --';
                        var cellName = item.cell ? '第 '+item.cell.row + ' 行，第' + item.cell.col + ' 列' : '-- --';
                        var goodsName = item.goods ? item.goods.name : '-- --';
                        self.formItems['user_name'].change(userName);
                        self.formItems['storefront_name'].change(storefrontName);
                        self.formItems['cabinet_name'].change(cabinetName);
                        self.formItems['cell_name'].change(cellName);
                        self.formItems['goods_name'].change(goodsName);
                    }
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面显示
    page.showStack.add('dataTable', function(){
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//模版管理-模版列表-配置文件
App.util.ns('Admin.Template.Message');
Admin.Template.Message.Conf = {
    columns: [
        {name: '用户ID', value: 'user_ids'},
        {name: '参数一', width: '80px', value: 'parameter_one'},
        {name: '参数二', width: '80px', value: 'parameter_two'},
        {name: '参数三', width: '80px', value: 'parameter_three'},
        {name: '参数四', width: '80px', value: 'parameter_four'},
        {name: '参数五', width: '80px', value: 'parameter_five'},
        {name: '参数六', width: '80px', value: 'parameter_six'},
        {name: '参数七', width: '80px', value: 'parameter_seven'},
        {name: '跳转链接', width: '80px', value: 'page'},
        {name: '模版类型', width: '90px', value: function(item){
            switch (item.type+'') {
                case '0':
                    return '商品降价通知';
            }
        }},
        {name: '是否发送', width: '80px', value: function(item){
            switch (item.status+'') {
                case '0':
                    return '未发送';
                case '1':
                    return '已发送';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'parameter_one', title: '参数一', maxLength: 50, rule: {
            type: 'str',
            range: [0, 50]
        }},
        {type: 'input', name: 'parameter_two', title: '参数二', maxLength: 50, rule: {
            type: 'str',
            range: [0, 50]
        }},
        {type: 'input', name: 'parameter_three', title: '参数三', maxLength: 50, rule: {
            type: 'str',
            range: [0, 50]
        }},
        {type: 'input', name: 'parameter_four', title: '参数四', maxLength: 50, rule: {
            type: 'str',
            range: [0, 50]
        }},
        {type: 'input', name: 'parameter_five', title: '参数五', maxLength: 50, rule: {
            type: 'str',
            range: [0, 50]
        }},
        {type: 'input', name: 'parameter_six', title: '参数六', maxLength: 50, rule: {
            type: 'str',
            range: [0, 50]
        }},
        {type: 'input', name: 'parameter_seven', title: '参数七', maxLength: 50, rule: {
            type: 'str',
            range: [0, 50]
        }},
        {type: 'input', name: 'page', title: '跳转链接', rule: {
            type: 'str'
        }},
        {type: 'radio', name: 'type', title: '模版类型',
            items: [
                ['0', '商品降价通知'],
            ],
            defaults: '0'
        }
    ]
};
//模版管理-模版列表
App.util.ns('Admin.Template.Message');
App.pages.add((function(){
    var NS = Admin.Template.Message;
    var page = new App.Page({
        name: 'template/message/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-volume-up"></i>',
            content: '模版消息管理'
        }, {
            content: '消息列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/template/message',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'type', title: '模版类型', width: '90px', items: [
                    [0, '商品通知'],
                ]},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [0, '未发送'],
                    [1, '已发送']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.template.message.create'},
                {type: 'globe', name: '推送所有用户', permission: 'op:admin.template.message', operation:function (dataTable) {
                    var temp_ids = dataTable.table.getSelectedIds();
                    if(temp_ids.length == 1){
                        $.ajax({
                            url: 'admin/template/message/message',
                            data:{message_id: temp_ids[0]},
                            type: "get",
                            async: true,
                            success: function (returnData){
                                if(returnData){
                                    App.util.hint.toast({
                                        type: 'success',
                                        text: '推送成功'
                                    }).delay(500);
                                }
                            },
                            error: function () {
                                App.util.hint.toast({
                                    type: 'error',
                                    text: '格式不对'
                                }).delay(500);
                            }
                        });
                    }else{
                        App.util.hint.alert({
                            text: '必须选中一条消息'
                        });
                    }
                }},
                {parent: 'view', permission: 'op:admin.template.message.detail'},
                {type: 'inline', permission: 'op:admin.template.message',conditions: [['status', '0']], name: '选择用户', operation: function(dataTable,tempmessage){
                    var win = dataTable.wins.get('sendMessage');
                    win.setTitle('批量选择用户');
                    win.show();
                    win.dataTable.table.frame.find('.chk-row').prop('checked', false).change();
                    //设置按钮
                    win.setBtns([(function(){
                        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
                        cancelBtn.click(function(){
                            win.hide();
                        });
                        return cancelBtn;
                    })(), (function(){
                        var saveBtn = $('<a class="btn btn-success btn-xs">保存</a>');
                        saveBtn.click(function(){
                            var userIds = win.dataTable.table.getSelectedIds();
                            var messageId = tempmessage.id;
                            if(userIds.length){
                                dataTable.postData({
                                    url: 'selectuser',
                                    alert: '保存成功！',
                                    reload: true,
                                    data: {
                                        message_id: messageId,
                                        user_ids: userIds.join(',')
                                    },
                                    after: function(){
                                        win.hide();
                                    }
                                });
                            }else{
                                App.util.hint.alert({
                                    text: '没有选择用户'
                                });
                            }
                        });
                        return saveBtn;
                    })()]);
                }},
                {type: 'inline', permission: 'op:admin.template.message.sendMessage',
                    operation: {type: 'change', url: 'sendMessage'},
                    name: '推送选择用户',conditions: [['status', '0']]
                },
                {parent: 'edit', permission: 'op:admin.template.message.update',conditions: [['status', '0']]},
                {parent: 'drop', permission: 'op:admin.template.message.delete'},
                {parent: 'multiDrop', permission: 'op:admin.template.message.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.template.message.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.SendMessage(dataTable), 'sendMessage');
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//模版管理-模版列表-选择用户
App.util.ns('Admin.Template.Message');
Admin.Template.Message.SendMessage = function(dataTable){
    var win = new App.Win({name: 'template_message', width: '500px'});
    //列表
    win.dataTable = new App.DataTable({
        baseUrl: '/admin/user/user',
        dataUrl: 'lists?status=1',
        table: {
            id: 'id',
            main: 0,
            //showId: false,
            columns: [
                {name: '用户名称', value: function(item){
                    return '/'+(item.user ? item.user.nickname+'/' : '')+item.nickname;
                }}
            ],
        },
        filter: [
            {type: 'keywords'}
        ],
        //floatable: false,
        //paginator: false
    });
    win.setContent(win.dataTable.frame);
    win.hide();
    //加载数据
    win.dataTable.loadData();
    return win;
};
//卡劵管理-卡劵列表-配置文件
App.util.ns('Admin.Card.Card');
Admin.Card.Card.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '价格', width: '80px', value: 'fee'},
        {name: '类型', width: '80px', value: function(item){
            switch (item.type+'') {
                case '1':
                    return '系统充值';
                case '2':
                    return '卡劵充值';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', rule: {
            type: 'str',
            range: [0, 50]
        }},
        {type: 'input', name: 'fee', title: '价格', rule: {
            type: 'str',
            range: [0, 50]
        }},
        {type: 'radio', name: 'type', title: '类型',
            items: [
                ['1', '系统充值'],
                ['2', '卡劵充值']
            ],
            defaults: '1'
        }
    ]
};
//卡劵管理-卡劵列表
App.util.ns('Admin.Card.Card');
App.pages.add((function(){
    var NS = Admin.Card.Card;
    var page = new App.Page({
        name: 'card/card/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-credit-card"></i>',
            content: '卡劵管理'
        }, {
            content: '卡劵列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/card/card',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: true,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'type', title: '类型', width: '80px', items: [
                    [1, '系统充值'],
                    [2, '卡劵充值'],
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.card.card.create'},
                {parent: 'view', permission: 'op:admin.card.card.detail'},
                {parent: 'edit', permission: 'op:admin.card.card.update'},
                {parent: 'drop', permission: 'op:admin.card.card.delete'},
                {parent: 'multiDrop', permission: 'op:admin.card.card.multiDelete'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//卡劵管理-充值列表-配置文件
App.util.ns('Admin.Card.Recharge');
Admin.Card.Recharge.Conf = {
    columns: [
        {name: '内容', value: 'content'},
        {name: '名称', width: '100px', value: 'name'},
        {name: '用户', width: '150px',value: function(item){
            return item.user ? item.user.nickname : '-- --';
        }},
        {name: '卡劵', width: '150px',value: function(item){
            return item.card ? item.card.name : '-- --';
        }},
        {name: '金额', width: '80px', value: 'fee'},
        {name: '是否充值', width: '80px', value: function(item){
            switch (item.status+'') {
                case '1':
                    return '未充值';
                case '2':
                    return '已充值';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', rule: {
            type: 'str',
            range: [0, 50]
        }},
        {type: 'selectLists', name: 'user_id', title: '用户',
            data_id: 'id',
            data_name: function(item){
                return item.id+':'+item.nickname;
            },
            dataTable: {
                baseUrl: '/admin/user/user',
                dataUrl: 'lists?status=1',
                data_id: 'id',
                data_name: 'name',
                table: {
                    id: 'id',
                    main: 0,
                    columns: [
                        {name: '用户名', value: 'nickname'}
                    ]
                },
                filter: [
                    {type: 'keywords'},
                ],
                height: '500px'
            }
        },
        {type: 'chosen', name: 'card_id', title: '卡劵',
            items: App.models.get('card-all'),
            item_key: 'id',
            item_name: 'name',
            rule: {
                type: 'num',
                range: [0, 250]
            },
            // onChange:function(self){
            //     var card = App.models.get('card-all');
            //     var card_index = [];
            //     for (var i=0;i<card.data.length;i++){
            //         var cards = card.data[i];
            //         if(cards.id == self.value()&&cards.id!=1){
            //             card_index.push([cards.id,cards.fee]);
            //         }
            //         console.log(card_index);
            //
            //     }
            //     self.form.formItems['fee'].config.items = card_index;
            //     self.form.formItems['fee'].flush();
            //     console.log(self)
            // }
        },
        {type: 'input', name: 'fee', title: '金额',
            rule: {
                type: 'str',
                range: [0, 50]
        }},
        {type: 'textarea', name: 'content', title: '内容',maxLength: 100, rule: {
            type: 'str',
            range: [0, 100]
        }}
    ]
};
//卡劵管理-充值列表
App.util.ns('Admin.Card.Recharge');
App.pages.add((function(){
    var NS = Admin.Card.Recharge;
    var page = new App.Page({
        name: 'card/recharge/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-credit-card"></i>',
            content: '卡劵管理'
        }, {
            content: '充值列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/card/recharge',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '是否充值', width: '80px', items: [
                    [1, '未充值'],
                    [2, '已充值'],
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.card.recharge.create'},
                {parent: 'view', permission: 'op:admin.card.recharge.detail'},
                {parent: 'edit', permission: 'op:admin.card.recharge.update',conditions: [['status', '1']]},
                {type: 'inline', permission: 'op:admin.card.recharge.rechargecard',
                    name: '充值', operation: {type: 'change', url: 'rechargecard'},
                    conditions: [['status', '1']]
                },
                {parent: 'drop', permission: 'op:admin.card.recharge.delete'},
                {parent: 'multiDrop', permission: 'op:admin.card.recharge.multiDelete'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//数据统计-体验列表-配置文件
App.util.ns('Admin.Experience.Experience');
Admin.Experience.Experience.Conf = {
    columns: [
        {name: '体验名称', value: 'name'},
        {name: '体验人', width: '100px', value: function(item){
            return item.user ? item.user.nickname : '-- --';
        }},
        {name: '体验柜子', width: '150px', value: function(item){
            return item.cabinet ? item.cabinet.name : '-- --';
        }},
        {name: '体验格子', width: '80px', value: function(item){
            return item.cell ? item.cell.code : '-- --';
        }},
        {name: '体验店', width: '150px', value: function(item){
            return item.storefront ? item.storefront.name : '-- --';
        }},
        {name: '体验商品', width: '130px', value: function(item){
            return item.goods ? item.goods.name : '-- --';
        }},
        {name: '起止时间', width: '90px', value: function(item){
            var startTime = item.start_time > 0 ? App.util.formator.dateTime(item.start_time).substr(11, 5) : '--:--';
            var endTime = item.end_time > 0 ? App.util.formator.dateTime(item.end_time).substr(11, 5) : '--:--';
            return startTime+' ~ '+endTime;
        }},
        {name: '使用时长', width: '80px', value: function(item){
            var time = 0;
            var isNum = function (val){
                // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除
                if(val === "" || val === null){
                    return false;
                }
                if(!isNaN(val)){
                    return true;
                }else{
                    return false;
                }
            };  
            if(item.status+'' === '2' || item.status+'' === '5' || item.status+'' === '4' && isNum(item.end_time) && isNum(item.start_time) && parseInt(item.end_time) > parseInt(item.start_time)){
                time = parseInt(item.end_time) - parseInt(item.start_time);
            }
            return time ? Math.ceil(time / 60) +'分' : '-- --';
        }},
        {name: '费用', width: '60px', value: 'fee'},
        {name: '体验状态', width: '80px', value: function(item){
            switch (item.status+'') {
                case '1':
                    return '体验中';
                case '2':
                    return '体验完';
                case '3':
                    return '不良记录';
                case '4':
                    return '已解决';
                case '5':
                    return '扫码进详情';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'}
    ]
};
//数据统计-体验列表
App.util.ns('Admin.Experience.Experience');
App.pages.add((function(){
    var NS = Admin.Experience.Experience;
    var page = new App.Page({
        name: 'experience/experience/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-bar-chart-o"></i>',
            content: '数据统计'
        }, {
            content: '体验记录'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/experience/experience',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '体验状态', width: '100px', items: [
                    [1, '体验中'],
                    [2, '体验完'],
                    [3, '不良记录'],
                    [4, '已解决'],
                    [5, '扫码进详情']
                ]}
            ],
            menu: [
                //{parent: 'view', permission: 'op:admin.experience.experience.detail'},
                //{parent: 'edit', permission: 'op:admin.experience.experience.update'},
                {parent: 'drop', permission: 'op:admin.experience.experience.delete'},
                {
                    type: 'inline', permission: 'op:admin.experience.experience.checked',
                    name: '完成', operation: {type: 'change', url: 'checked'},
                    conditions: [['status', '1']]
                },
                {
                    type: 'inline', permission: 'op:admin.experience.experience.checking',
                    name: '回滚', operation: {type: 'change', url: 'checking'},
                    conditions: [['status', '2']]
                },
                {
                    type: 'inline', permission: 'op:admin.experience.experience.solve',
                    name: '已解决', operation: {type: 'change', url: 'solve'},
                    conditions: [['status', '3']]
                },
                {parent: 'multiDrop', permission: 'op:admin.experience.experience.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.experience.experience.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//数据统计--订单报表
App.util.ns('Admin.Experience.Stats');
App.pages.add((function(){
    var NS = Admin.Experience.Stats;
    var page = new App.Page({
        name: 'experience/stats/index'
    });
    page.jobs = [];
    page.flushData = function(month){
        App.util.request.getData({
            url: 'admin/experience/stats/index',
            data: {
                month: month
            },
            loading: new App.Loading({container: page.contentContainer}),
            success: function(data){
                console.log(page.jobs)
                for(var i in page.jobs){
                    page.jobs[i](data);
                }
            }
        });
    };
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-bar-chart-o"></i>',
            content: '数据统计'
        }, {
            content: '订单报表'
        }]);
        this.setContent($(`
            <style>
                .filter-container{
                    width: 100%;
                    height: 34px;
                    margin-top: 15px;
                }
                .date-name{
                    width: 120px;
                    height: 34px;
                    display: inline-block;
                    float: left;
                    line-height: 34px;
                }
                .date-selector{
                    width: 220px;
                    height: 34px;
                    display: inline-block;
                    margin-left: 10px;
                    float: left;
                }
                .title-container{
                    border-bottom: 1px solid #ededed;
                    position: relative;
                    padding: 10px 0;
                    margin: 15px 0 0 0;
                }
                .title-flag{
                    border-left: 5px solid #f26f20;
                    margin-right: 10px;
                }
                .title-explain{
                    color: #999;
                    font-size: 12px;
                    position: absolute;
                    right: 0;
                    top: 10px;
                }
                .stats-block{
                    width: 100%;
                    height: 150px;
                }
                .stats-block-top{
                    width: 100%;
                    height: 96px;
                    border: 1px solid #ccc;
                    text-align: center;
                }
                .stats-block-bottom{
                    width: 100%;
                    height: 54px;
                }
                .stats-block-left{
                    width: 50%;
                    height: 100%;
                    float: left;
                    border-left: 1px solid #ccc;
                    border-bottom: 1px solid #ccc;
                    text-align: center;
                    padding-top: 6px;
                }
                .stats-block-right{
                    width: 50%;
                    height: 100%;
                    float: left;
                    border-left: 1px solid #ccc;
                    border-right: 1px solid #ccc;
                    border-bottom: 1px solid #ccc;
                    text-align: center;
                    padding-top: 6px;
                }
                .stats-block-value{
                    color: #454545;
                    font-size: 34px;
                }
                .stats-block-text{
                    color: #999;
                    font-size: 14px;
                }
                .stats-block-value-sm{
                    color: #454545;
                    font-size: 14px;
                }
                .stats-block-text-sm{
                    color: #999;
                    font-size: 12px;
                }
            </style>
            <div style="padding: 0 15px;">
                <div class="filter-container">
                    <div class="date-name">
                        <span class="title-flag"></span>
                        <span>选择要统计的月份</span> 
                    </div>
                    <div class="date-selector"></div>
                </div>
                <div class="title-container">
                    <span class="title-flag"></span> 
                    <span><span class="month-name"></span>订单数据概览</span> 
                    <div class="title-explain">"--" 代表数据更新中</div>
                </div>
                <div class="row" style="margin-top: 10px;">
                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="stats-block">
                            <div class="stats-block-top">
                                <span class="stats-block-value data-user-total">--</span>
                                <div class="stats-block-text">
                                    <span>总订单数</span>
                                </div>
                            </div>
                            <div class="stats-block-bottom">
                                <div class="stats-block-left">
                                    <span class="stats-block-value-sm data-user-incr-month">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较上个月</span>
                                    </div>
                                </div>
                                <div class="stats-block-right">
                                    <span class="stats-block-value-sm data-user-incr-avg">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较平均值</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="stats-block">
                            <div class="stats-block-top">
                                <span class="stats-block-value data-times-total">--</span>
                                <div class="stats-block-text">
                                    <span>总订单完成数（次）</span>
                                </div>
                            </div>
                            <div class="stats-block-bottom">
                                <div class="stats-block-left">
                                    <span class="stats-block-value-sm data-times-incr-month">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较上个月</span>
                                    </div>
                                </div>
                                <div class="stats-block-right">
                                    <span class="stats-block-value-sm data-times-incr-avg">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较平均值</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="stats-block">
                            <div class="stats-block-top">
                                <span class="stats-block-value data-time-total">--</span>
                                <div class="stats-block-text">
                                    <span>总待支付数（次）</span>
                                </div>
                            </div>
                            <div class="stats-block-bottom">
                                <div class="stats-block-left">
                                    <span class="stats-block-value-sm data-time-incr-month">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较上个月</span>
                                    </div>
                                </div>
                                <div class="stats-block-right">
                                    <span class="stats-block-value-sm data-time-incr-avg">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较平均值</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="stats-block">
                            <div class="stats-block-top">
                                <span class="stats-block-value data-amount-total">--</span>
                                <div class="stats-block-text">
                                    <span>总收入（元）</span>
                                </div>
                            </div>
                            <div class="stats-block-bottom">
                                <div class="stats-block-left">
                                    <span class="stats-block-value-sm data-amount-incr-month">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较上个月</span>
                                    </div>
                                </div>
                                <div class="stats-block-right">
                                    <span class="stats-block-value-sm data-amount-incr-avg">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较平均值</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="title-container">
                    <span class="title-flag"></span> 
                    <span><span class="month-name"></span>订单状态对比分析</span> 
                    <div class="title-explain"></div>
                </div>
                <div class="row" style="margin-top: 10px;">
                    <div class="col-sm-12">
                        <div class="panel panel-default" style="border-radius: 0;">
                            <div class="panel-body">
                                <div class="goods-month-times-percent" style="height: 320px;">
                                </div>
                            </div>
                            <div class="panel-footer text-center" style="background-color: #fff;border-radius: 0;">
                                <span class="month-name"></span>订单状态占比
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row" style="margin-top: 10px;">
                    <div class="col-sm-12">
                        <div class="panel panel-default" style="border-radius: 0;">
                            <div class="panel-body">
                                <div class="goods-month-time-percent" style="height: 320px;">
                                </div>
                            </div>
                            <div class="panel-footer text-center" style="background-color: #fff;border-radius: 0;">
                                <span class="month-name"></span>费用占比
                            </div>
                        </div>
                    </div>
                </div>
                <!--<div class="title-container">
                    <span class="title-flag"></span> 
                    <span><span class="month-name"></span>各仪器使用趋势分析</span> 
                    <div class="title-explain"></div>
                </div>
                <div class="row" style="margin-top: 10px;">-->
                    <!--<div class="col-sm-12">-->
                        <!--<div class="panel panel-default" style="border-radius: 0;">-->
                            <!--<div class="panel-body">-->
                                <!--<div class="goods-month-times-trend" style="height: 410px;">-->
                                <!--</div>-->
                            <!--</div>-->
                            <!--<div class="panel-footer text-center" style="background-color: #fff;border-radius: 0;">-->
                                <!--<span class="month-name"></span>仪器使用次数趋势-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                <!--</div>-->
                <!--<div class="row" style="margin-top: 10px;">-->
                    <!--<div class="col-sm-12">-->
                        <!--<div class="panel panel-default" style="border-radius: 0;">-->
                            <!--<div class="panel-body">-->
                                <!--<div class="goods-month-time-trend" style="height: 410px;">-->
                                <!--</div>-->
                            <!--</div>-->
                            <!--<div class="panel-footer text-center" style="background-color: #fff;border-radius: 0;">-->
                                <!--<span class="month-name"></span>仪器使用时长趋势-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                <!--</div>-->
            </div>
        `));
        var date = new App.Form.DateMonth({
            name: 'month',
            onChange: function (self){
                var month = App.util.formator.date(self.value()).substring(0, 7);
                page.flushData(month);
            }
        });
        page.frame.find('.filter-container .date-selector').append(date.frame);
        page.jobs.push(function(data){
            page.frame.find('.month-name').text(data.monthName);
            var global = data.global;
            //总使用用户
            page.frame.find('.data-user-total').text(global.user.total);//用户总数
            page.frame.find('.data-user-incr-month').text(global.user.incrMonth);//较上个月增长
            page.frame.find('.data-user-incr-avg').text(global.user.incrAvg);//较平均值增长
            //使用次数
            page.frame.find('.data-times-total').text(global.times.total);//总使用次数
            page.frame.find('.data-times-incr-month').text(global.times.incrMonth);//较上个月增长
            page.frame.find('.data-times-incr-avg').text(global.times.incrAvg);//较平均值增长
            //总使用时长
            //var totalTime = global.time.total ? parseFloat(parseInt(global.time.total)/3600).toFixed(2) : 0;
            page.frame.find('.data-time-total').text(global.time.total);//总使用时长
            page.frame.find('.data-time-incr-month').text(global.time.incrMonth);//较上个月增长
            page.frame.find('.data-time-incr-avg').text(global.time.incrAvg);//较平均值增长
            //总产生费用
            //page.frame.find('.data-amount-total').text(parseFloat(global.amount.total).toFixed(2));//总费用
            page.frame.find('.data-amount-total').text(global.amount.total);
            page.frame.find('.data-amount-incr-month').text(global.amount.incrMonth);//较上个月增长
            page.frame.find('.data-amount-incr-avg').text(global.amount.incrAvg);//较平均值增长
            //各仪器使用情况对比
            var timesData = data.group.times;
            var timeData = data.group.time;
            var timesItems = [];
            var timeItems = [];
            for(var i in timesData){
                timesItems.push(timesData[i].name);
            }
            for(var i in timeData){
                timeItems.push(timeData[i].name);
            }
            echarts.init(page.frame.find('.goods-month-times-percent').first()[0]).setOption({
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    x: 'left',
                    data: timesItems
                },
                series: [
                    {
                        name:'访问来源',
                        type:'pie',
                        radius: ['40%', '55%'],
                        data: timesData
                    }
                ]
            });
            echarts.init(page.frame.find('.goods-month-time-percent').first()[0]).setOption({
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    x: 'left',
                    data: timeItems
                },
                series: [
                    {
                        name:'访问来源',
                        type:'pie',
                        radius: ['40%', '55%'],
                        data: timeData
                    }
                ]
            });



            // //各仪器使用使用趋势
            // var goodsTimesData = data.goods.times;
            // var goodsTimeData = data.goods.time;
            // echarts.init(page.frame.find('.goods-month-times-trend').first()[0]).setOption({
            //     tooltip: {
            //         trigger: 'axis'
            //     },
            //     legend: {
            //         type: 'scroll',
            //         orient: 'vertical',
            //         x: 'left',
            //         top: '20px',
            //         data: goodsTimesData.goods
            //     },
            //     grid: {
            //         top: '20px',
            //         left: '220px',
            //         right: '20px',
            //         bottom: '10px',
            //         containLabel: true
            //     },
            //     xAxis: {
            //         type: 'category',
            //         boundaryGap: false,
            //         data: goodsTimesData.days
            //     },
            //     yAxis: {
            //         type: 'value'
            //     },
            //     series: goodsTimesData.data
            // });
            // echarts.init(page.frame.find('.goods-month-time-trend').first()[0]).setOption({
            //     tooltip: {
            //         trigger: 'axis'
            //     },
            //     legend: {
            //         type: 'scroll',
            //         orient: 'vertical',
            //         x: 'left',
            //         top: '20px',
            //         data: goodsTimeData.goods
            //     },
            //     grid: {
            //         top: '20px',
            //         left: '220px',
            //         right: '20px',
            //         bottom: '10px',
            //         containLabel: true
            //     },
            //     xAxis: {
            //         type: 'category',
            //         boundaryGap: false,
            //         data: goodsTimeData.days
            //     },
            //     yAxis: {
            //         type: 'value'
            //     },
            //     series: goodsTimeData.data
            // });
            
        });
        page.flushData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
    });
    return page;
})());
//数据统计-货柜入驻列表-配置文件
App.util.ns('Admin.Experience.Enter');
Admin.Experience.Enter.Conf = {
    columns: [
        {name: '标题', value: 'title'},
        {name: '网页链接', width: '350px', value: 'web_url'},
        {name: '入驻时间', width: '100px', value: function(item){
            return App.util.formator.date(item.enter_time);
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'img', name: 'enter_img', title: '入驻图片', rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'input', name: 'title', title: '标题', rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'input', name: 'web_url', title: '网页链接', rule: {
            type: 'str'
        }},
        {type: 'date', name: 'enter_time', title: '入驻时间', required: true},
        {type: 'textarea', name: 'enter_info', title: '简介',maxLength: 100, rule: {
            type: 'str',
            range: [0, 100]
        }}
    ]
};
//数据统计-体验列表
App.util.ns('Admin.Experience.Enter');
App.pages.add((function(){
    var NS = Admin.Experience.Enter;
    var page = new App.Page({
        name: 'experience/enter/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-bar-chart-o"></i>',
            content: '数据统计'
        }, {
            content: '美文推荐'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/experience/enter',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.experience.enter.create'},
                {parent: 'view', permission: 'op:admin.experience.enter.detail'},
                {parent: 'edit', permission: 'op:admin.experience.enter.update'},
                {
                    type: 'inline',
                    name: '关联商品',
                    permission: 'gp:admin/experience/enter',
                    operation: function(dataTable, enter){
                        var win = dataTable.wins.get('relationgoods');
                        win.form.change({
                            id: enter.id,
                        });
                        win.show();
                    }
                },
                {parent: 'drop', permission: 'op:admin.experience.enter.delete'},
                {parent: 'multiDrop', permission: 'op:admin.experience.enter.multiDelete'},
                //{parent: 'oplog', permission: 'op:admin.experience.experience.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            dragSort:{
                permission: 'op:admin.experience.enter.sort',
                url:'sort',
                filed:'sort'
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.Relationgoods(dataTable), 'relationgoods');
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//订单管理-订单售后-运单填写
App.util.ns('Admin.Experience.Enter');
Admin.Experience.Enter.Relationgoods = function(dataTable){
    var win = new App.Win({
        name: 'relationgoods',
        title: '关联商品',
        width: '720px'
    });

    //表单提交
    var form = new App.Form({
        items: [
            {type: 'hidden', name: 'id'},
            {type: 'selectLists', name: 'goods_id', title: '商品名称',
                data_id: 'id', 
                data_name: function(item){
                    return item.id+':'+item.name;
                },
                dataTable: {
                    baseUrl: '/admin/goods/goods',
                    dataUrl: 'lists?status=1',
                    data_id: 'id',
                    data_name: 'name',
                    table: {
                        id: 'id',
                        main: 0,
                        columns: [
                            {name: '商品名', value: 'name'}
                        ]
                    },
                    filter: [
                        {type: 'keywords'},
                        {type: 'timeRange'}
                    ],
                    height: '720px'
                }
            },
            {type: 'input', name: 'number', title: '商品体验人数', rule: {
                type: 'num'
            }}
        ]
    });
    form.fix(win.contentContainer);
    win.form = form;
    win.changeEnter = function(enter){
        win.enter = enter;
        return win;
    };

    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">提交</a>');
        saveBtn.click(function(){
            var formData = form.getData();
            console.log(formData);
            App.util.request.postData({
                url: '/admin/experience/enter/creategoods',
                data: {
                    id: formData['id'],
                    goods_id: formData['goods_id'],
                    number: formData['number']
                },
                loading: new App.Loading(win.contentContainer),
                success: function(){
                    App.util.hint.toast({
                        type: 'ok',
                        text: '提交成功'
                    }).delay(500, function(){
                        win.hide();
                    });
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};
//意见反馈-反馈列表-配置文件
App.util.ns('Admin.Feedback.Feedback');
Admin.Feedback.Feedback.Conf = {
    columns: [
        // {name: '体验名称', value: function(item){
        //     return item.experience ? item.experience.name : '-- --';
        // }},
        {name: '反馈标题', value: 'title'},
        {name: '反馈类型', width: '120px', value: function(item){
            switch (item.type+'') {
                case '1':
                    return '体验记录反馈信息';
                case '2':
                    return '小程序端用户反馈';
            }
        }},
        {name: '详细说明', width: '220px', value: 'content'},
        {name: '用户', width: '100px', value: function(item){
            return item.user ? item.user.nickname : '-- --';
        }},
        {name: '联系方式', width: '120px', value: 'contact'},
        {name: '处理状态', width: '80px', value: function(item){
            switch (item.status+'') {
                case '0':
                    return '未处理';
                case '1':
                    return '已处理';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'title', title: '标题', required: true, maxLength: 80, rule: {
            type: 'str',
            range: [1, 160]
        }},
        {type: 'chosen', name: 'type', title: '类型', required: true, items:[
            ['1', '体验记录反馈信息'],
            ['2', '小程序端用户反馈']
        ], defaults: '1'},
        {type: 'textarea', name: 'manage', title: '处理内容', maxLength: 200, rule: {
            type: 'str',
            range: [0, 200]
        }}
    ]
};
//意见反馈-反馈列表
App.util.ns('Admin.Feedback.Feedback');
App.pages.add((function(){
    var NS = Admin.Feedback.Feedback;
    var page = new App.Page({
        name: 'feedback/feedback/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-question-circle-o"></i>',
            content: '意见反馈'
        }, {
            content: '反馈列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/feedback/feedback',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'type', title: '反馈类型', width: '120px', items: [
                    [1, '体验记录反馈信息'],
                    [2, '小程序端用户反馈']
                ]},
                {type: 'select', name: 'status', title: '处理状态', width: '120px', items: [
                    [0, '未处理'],
                    [1, '已处理']
                ]}
            ],
            menu: [
                //{parent: 'add', permission: 'op:admin.feedback.feedback.create'},
                {parent: 'view', permission: 'op:admin.feedback.feedback.detail'},
                {parent: 'edit', permission: 'op:admin.feedback.feedback.update'},
                {type: 'inline', permission: 'op:admin.feedback.feedback.finish', name: '完成', operation: {type: 'change', url: 'finish'}, conditions: [['status', '0']]},
                {type: 'inline', permission: 'op:admin.feedback.feedback.finied', name: '回滚', operation: {type: 'change', url: 'finied'}, conditions: [['status', '1']]},
                {parent: 'drop', permission: 'op:admin.feedback.delete'},
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.feedback.feedback.multiFinish', name: '完成', operation: {type: 'change', url: 'multiFinish', confirm: true}},
                    {type: 'multi', permission: 'op:admin.feedback.feedback.multiFinied', name: '回滚', operation: {type: 'change', url: 'multiFinied', confirm: true}}
                ], permission:[
                    'op:admin.feedback.feedback.multiFinish',
                    'op:admin.feedback.feedback.multiFinied'
                ]},
                {parent: 'multiDrop', permission: 'op:admin.feedback.feedback.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.feedback.feedback.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//官网管理-反馈信息-配置文件
App.util.ns('Admin.Website.WebsiteFb');
Admin.Website.WebsiteFb.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '电话', width: '120px',value: 'phone'},
        {name: '邮箱', width: '120px',value: 'email'},
        {name: '状态', width: '80px',value: function(item){
            switch (item.status+'') {
                case '0':
                    return '待处理';
                case '1':
                    return '已处理';
            }
        }},
        {name: '反馈时间', width: '140px', value: function(item){
            return App.util.formator.dateTime(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'hidden', name: 'ua'},
        {type: 'input', name: 'name', title: '名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'input', name: 'phone', title: '电话', rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'input', name: 'email', title: '邮箱', rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'textarea', name: 'content', title: '内容', required: true, maxLength: 2000, rule: {
            type: 'str',
            range: [1, 4000]
        }}
    ]
};
//官网管理-反馈信息
App.util.ns('Admin.Website.WebsiteFb');
App.pages.add((function(){
    var NS = Admin.Website.WebsiteFb;
    var page = new App.Page({
        name: 'website/websiteFb/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-envelope"></i>',
            content: '官网管理'
        }, {
            content: '反馈信息'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/website/websiteFb',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [0, '待处理'],
                    [1, '已处理']
                ]}
            ],
            menu: [
                {parent: 'view', permission: 'op:admin.website.websiteFb.detail'},
                {type: 'inline', permission: 'op:admin.website.websiteFb.active', name: '完成',
                    operation: {type: 'change', url: 'active'}, conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.website.websiteFb.actived', name: '回滚',
                    operation: {type: 'change', url: 'actived'}, conditions: [['status', '1']]
                },
                {parent: 'drop', permission: 'op:admin.website.websiteFb.delete'},
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.website.websiteFb.multiActive', name: '完成', operation: {type: 'change', url: 'multiActive', confirm: true}},
                    {type: 'multi', permission: 'op:admin.website.websiteFb.multiActived', name: '回滚', operation: {type: 'change', url: 'multiActived', confirm: true}}
                ], permission:[
                    'op:admin.website.websiteFb.multiActive',
                    'op:admin.website.websiteFb.multiActived'
                ]},
                {parent: 'multiDrop', permission: 'op:admin.website.websiteFb.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.website.websiteFb.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//货柜管理-换货申请
App.util.ns('Admin.Apply.Exchange');
Admin.Apply.Exchange.ExchangeApply = function(dataTable){
    var win = new App.Win({
        name: 'exchange_apply',
        title: '换货申请',
        width: '720px'
    });
    //列表
    win.dataTable = new App.DataTable({
        baseUrl: '/admin/cabinet/cell',
        dataUrl: 'lists',
        table: {
            id: 'id',
            main: 1,
            showId: false,
            withSelect: false,
            columns: [
                {name: '位置', width: '90px', value: function(item){
                    return item.row + ' 行，' + item.col + ' 列';  
                }},
                {name: '原商品', value: function(item){
                    var name = item.goods ? item.goods.name : '未分配';
                    return $('<span style="margin: 0 6px">'+name+'</span>');
                }},
                {name: '期望商品', width: '350px', value: function(item){
                    var selector = new App.Form.SelectLists({
                        type: 'selectLists', 
                        name: 'id', 
                        title: '期望商品', 
                        data_id: 'goods_id', 
                        width: '600px',
                        data_name: function(item){
                            return item.id+': '+item.name;
                        },
                        dataTable: {
                            baseUrl: '/client/apply/exchange/goods',
                            dataUrl: 'lists',
                            data_id: 'id',
                            data_name: 'name',
                            table: {
                                id: 'id',
                                main: 0,
                                columns: [
                                    {name: '商品名', value: 'name'}
                                ]
                            },
                            filter: [
                                {type: 'keywords'}
                            ]
                        },
                        detail: {
                            form: {
                                items: App.util.copy(Admin.Goods.Goods.Conf.form)
                            }
                        }
                    });
                    selector.dataTable.win.fix(win.frame);
                    if(selector.detail){
                        selector.detail.win.fix(win.frame);
                    }
                    if(item.target){
                        selector.change(item.target.id, item.target.name, item.target);
                    }
                    selector.view();
                    return selector.frame;
                }}
            ]
        },
        after: function(self){
            self.frame.find('> .header').remove();
            self.frame.find('.data-table').addClass('table-bordered').removeClass('table-hover');
            self.fix(win.contentContainer);
        }
    });
    win.change = function(cabinet, info){
        win.setTitle('换货申请 - '+cabinet.name);
        var data = JSON.parse(info);
        win.dataTable.table.flushItmes(data);
        win.dataTable.frame.find('tbody td').css({padding: '0'});
        return win;
    };
    win.hide();
    return win;
};
//货柜管理-换货申请
App.util.ns('Admin.Apply.Exchange');
App.pages.add((function(){
    var NS = Admin.Apply.Exchange;
    var page = new App.Page({
        name: 'admin/apply/exchange/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-handshake-o"></i>',
            content: '货柜管理'
        }, {
            content: '换货申请'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/apply/exchange',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: [
                    {name: '客户', value: function(item){
                        return item.client ? item.client.name : '-- --';
                    }},
                    {name: '货柜', width: '150px', value: function(item){
                        return item.cabinet ? item.cabinet.name : '-- --';
                    }},
                    {name: '状态', width: '90px',value: function(item){
                        switch (item.status+'') {
                            case '0':
                                return '未处理';
                            case '1':
                                return '已处理';
                        }
                    }},
                    {name: '申请日期', width: '80px', value: function(item){
                        return App.util.formator.date(item.created_at);
                    }}
                ]
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [0, '未处理'],
                    [1, '已处理']
                ]}
            ],
            menu: [
                {
                    type: 'inline',
                    name: '查看',
                    icon: '<i class="fa fa-eye"></i>',
                    floatable: true,
                    permission: 'op:admin.apply.exchange.detail',
                    operation: function(dataTable, item){
                        var win = dataTable.wins.get('exchangeApply').show();
                        win.change(item.cabinet, item.goods_info).show();
                    }
                },
                {type: 'inline', permission: 'op:admin.apply.exchange.finish', name: '处理完成', operation: {type: 'change', url: 'finish'}, conditions: [['status', '0']]},
                {parent: 'drop', permission: 'op:admin.apply.exchange.delete'},
                {type: 'multi', name: '状态', openable: true, permission: 'op:admin.apply.exchange.multiFinish', items: [{
                        type: 'multi', permission: 'op:admin.goods.goods.multiOnline', name: '处理完成', operation: {
                        type: 'change', url: 'multiFinish', confirm: true
                    }}]
                },
                {parent: 'multiDrop', permission: 'op:admin.apply.exchange.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.apply.exchange.getOpLogs'}
            ],
            after: function(dataTable){
                dataTable.wins.add(new NS.ExchangeApply(dataTable), 'exchangeApply');
            }
        });
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面显示
    page.showStack.add('dataTable', function(){
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//货柜管理-货柜列表-配置文件
App.util.ns('Client.Goods');
Client.Goods.Conf = {
    columns: [
        {name: '商品名', value: 'name',width: '300px',},
        {name: '进货价', width: '60px',value: 'price_cost'},
        {name: '限价', width: '60px',value: 'fixed_price'},
        {name: '商城价', width: '60px',value: 'price_original'},
        //{name: '走路抵金', width: '65px',value: 'moneylimit'},
        //{name: '活动价', width: '80px',value: 'price_lower'},
        {name: '体验价', width: '60px',value: 'price_lowest'},
        //{name: '体验抵金', width: '65px',value: 'experience_payment'},
        {name: '品牌名', width: '60px',value: function (item) {
            return item.brand ? item.brand.name : '-- --';
        }},
        {name: '型号', width: '60px',value: 'models'},
        {name: '库存', width: '60px',value: 'inventory'},
        {name: '卖出数量', width: '65px',value: 'sell_total'},
        {name: '关键词', width: '100px',value: 'classify'},
        {name: '可否体验', width: '65px',value: function(item){
            switch (item.is_experience+'') {
                case '0':
                    return '可体验';
                case '1':
                    return '不可体验';
            }
        }},
        {name: '是否限购', width: '65px',value: function(item){
            switch (item.buylimit+'') {
                case '0':
                    return '否';
                case '1':
                    return '是';
            }
        }},
        {name: '状态', width: '60px',value: function(item){
            switch (item.status+'') {
                case '0':
                    return '下线';
                case '1':
                    return '在线';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'img', name: 'icon', title: '图标',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'video', name: 'video', title: '介绍视频',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'input', name: 'price_cost', title: '进货价', rule: {
            type: 'str',
            range: [0, 30]
        }},
        {type: 'input', name: 'fixed_price', title: '限价', rule: {
            type: 'str',
            range: [0, 30]
        }},
        {type: 'input', name: 'price_original', title: '商城价', required: true,
            comment: '请输入带两位小数的数字。如88.00',
            rule: {
                type: 'float',
                range: [1],
                decimal: [2, 2]
        }},
        {type: 'input', name: 'price_lowest', title: '体验价', required: true,
            comment: '请输入带两位小数的数字。如88.00',
            rule: {
                type: 'float',
                range: [1],
                decimal: [2, 2]
        }},
        {type: 'selectLists', name: 'brand_id', title: '品牌',
            data_id: 'id',
            data_name: function(item){
                return item.id+':'+item.name;
            },
            dataTable: {
                baseUrl: '/admin/goods/brand',
                dataUrl: 'lists?status=1',
                data_id: 'id',
                data_name: 'name',
                table: {
                    id: 'id',
                    main: 0,
                    columns: [
                        {name: '品牌名', value: 'name'}
                    ]
                },
                filter: [
                    {type: 'keywords'}
                ],
                height: '720px'
            }
        },
        {type: 'tags', name: 'models', title: '型号', rule: {
            type: 'str',
            range: [0,200]
        }},
        {type: 'input', name: 'inventory', title: '库存',required: true, rule: {
            type: 'num'
        }},
        {type: 'input', name: 'sell_total', title: '卖出数量',required: true, rule: {
            type: 'num'
        }},
        {type: 'checkbox', name: 'types', title: '类型', required: true,
            items: App.models.get('goodstypes'),
            item_key: 'id',
            item_name: 'name',
            rule: {
                type: 'str',
                range: [1, 250]
        }},
        {type: 'tags', name: 'classify', title: '关键词', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 200]
        }},
        {type: 'client-goods-spec-specifications', name: 'spec', title: '规格',
            comment: '例如：颜色  红,黄(必须用英文逗号)',
        },
        {type: 'radio', name: 'is_experience', title: '可否体验', required: true,
            items: [
                ['0', '可体验'],
                ['1', '不可体验']
            ],
            defaults: '0'
        },
        {type: 'radio', name: 'buylimit', title: '是否限购', required: true,
            items: [
                ['0', '否'],
                ['1', '是']
            ],
            defaults: '0'
        },
        {type: 'imgs', name: 'posters', title: '轮播图', rule: {
            type: 'str',
            // range: [0, 1000]
        }},
        {type: 'imgs', name: 'imgs', title: '商品详情图', rule: {
            type: 'str',
            // range: [0, 1000]
        }},
        {type: 'imgs', name: 'imgs_parameter', title: '购物须知图', rule: {
            type: 'str',
            // range: [0, 1000]
        }},
        {type: 'textarea', name: 'discription', title: '商品简介',maxLength: 100, rule: {
            type: 'str',
            range: [0, 100]
        }},
        {type: 'textarea', name: 'introduction', title: '功能介绍',maxLength: 500, rule: {
            type: 'str',
            range: [0, 500]
        }}
    ]
};
//商品管理-规格
App.util.ns('Client.Goods.Form');
Client.Goods.Form.Specifications = function(config){
    this.config = config;
    this.name = this.config.name;
    this.form = null;
    this.frame = null;
    this.items = [];
    this.mainItem = null;
    //初始化
    this.init();
};
Client.Goods.Form.Specifications.prototype = {
    constructor: Client.Goods.Form.Specifications,
    init: function(){
        var self = this;
        this.frame = $([
            '<div class="program-epg-container">',
            '   <div class="item main">',
            '       <div class="input-group" style="width:100%">',
            '           <input type="text" class="form-control spec" placeholder="规格(例如：颜色)">',
            '           <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            '           <input type="text" class="form-control param" placeholder="参数(例如：红,黄)">',
            //'           <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            // '           <input type="text" class="form-control unit" placeholder="计费单位">',
            // '           <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            // '           <input type="text" class="form-control price" placeholder="价格">',
            '           <span class="input-group-btn">',
            '               <button class="btn btn-default btn-sm btn-add" type="button" style="border-radius: 0;"><i class="fa fa-plus"></i></button>',
            '           </span>',
            '       </div>',
            '       <span class="form-static" style="display: none;"></span>',
            '   </div>',
            '</div>'
        ].join(''));
        this.frame.find('.spec').css({float: 'left', width: '115px', height: '30px'});
        this.frame.find('.input-group-addon').css({float: 'left', width: '30px', height: '30px'});
        this.frame.find('.param').css({float: 'left', width: '220px', height: '30px'});
        // this.frame.find('.unit').css({float: 'left', width: '90px', height: '30px'});
        // this.frame.find('.price').css({float: 'left', width: 'calc(100% - 390px)', height: '30px'});
        this.frame.find('.input-group-btn').css({float: 'left'});
        this.frame.find('.btn-add').click(function(){
            self.getItem().appendTo(self.frame);
        });
        return this;
    },
    setForm: function(form){
        this.form = form;
    },
    getItem: function(){
        this.itemCount += 1;
        var self = this;
        var item = $([
            '<div class="item">',
            '    <div class="input-group" style="width:100%">',
            '        <input type="text" class="form-control spec" placeholder="规格">',
            '        <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            '        <input type="text" class="form-control param" placeholder="参数">',
            // '        <span class="input-group-addon" style="border-left: none;border-right: none;">></span>',
            // '        <input type="text" class="form-control unit" placeholder="计费单位">',
            // '        <span class="input-group-addon" style="border-left: none;border-right: none;">-</span>',
            // '        <input type="text" class="form-control price" placeholder="价格">',
            '        <span class="input-group-btn">',
            '            <button class="btn btn-default btn-sm btn-drop" type="button" style="border-radius: 0;"><i class="fa fa-times"></i></button>',
            '        </span>',
            '    </div>',
            '    <span class="form-static" style="display: none;"></span>',
            '</div>'
        ].join(''));
        item.find('.spec').css({float: 'left', width: '115px', height: '30px'});
        item.find('.input-group-addon').css({float: 'left', width: '30px', height: '30px'});
        item.find('.param').css({float: 'left', width: '220px', height: '30px'});
        //item.find('.unit').css({float: 'left', width: '90px', height: '30px'});
        //item.find('.price').css({float: 'left', width: 'calc(100% - 390px)', height: '30px'});
        item.find('.input-group-btn').css({float: 'left'});
        item.find('.btn-drop').click(function(){
            item.remove();
        });
        return item;
    },
    change: function(val){//改变
        this.reset();
        val = JSON.parse(val) ? JSON.parse(val) : '';
        for(var i in val){
            var item = val[i];
            //var price = item['price'] ? item['price'] : '';
            var spec = item['spec'] ? item['spec'] : '';
            var param = item['param'] ?item['param'] : '';
            if(i+'' === '0'){
                //this.frame.find('.item.main .price').val(price);
                this.frame.find('.item.main .spec').val(spec);
                this.frame.find('.item.main .param').val(param);
            }else{
                var itemObj = this.getItem();
                //itemObj.find('.price').val(price);
                itemObj.find('.spec').val(spec);
                itemObj.find('.param').val(param);
                itemObj.appendTo(this.frame);
            }
        }
        return this;
    },
    view: function(){//查看
        this.flushView();
        this.frame.find('.item > .input-group').hide();
        this.frame.find('.item > .form-static').show();
        return this;
    },
    flushView: function(){
        this.frame.find('.item').each(function(){
            var text = '规格： <span style="color: blue;">'+$(this).find('.spec').val() + '</span> ，参数： <span style="color: blue;">' + $(this).find('.param').val()+'</span> ';
            $(this).find('.form-static').html('<span style="font-size: 13px;">'+text+'</span>');
        });
    },
    reset: function(){
        this.frame.find('.item').each(function(){
            if(!$(this).hasClass('main')){
                $(this).remove();
            }
        });
        this.frame.find('.item.main').find('select').val('').change();
        this.frame.find('.item.main').find('input').val('').change();
        this.frame.find('.item > .input-group').show();
        this.frame.find('.item > .form-static').hide();
        return this;
    },
    edit: function(){
        this.frame.find('.item > .input-group').show();
        this.frame.find('.item > .form-static').hide();
        return this;
    },
    value: function(){
        var self = this;
        var data = [];
        this.frame.find('.item').each(function(){
            //var price = $(this).find('.price').val();
            var spec = $(this).find('.spec').val();
            var param = $(this).find('.param').val();
            data.push({
                //price: price,
                spec: spec,
                param: param
            });
        });
        return JSON.stringify(data);
    }, 
    enable: function(){
        this.frame.find('select').prop('disabled', false);
        this.frame.find('input').prop('disabled', false);
        return this;
    },
    disable: function(){
        this.frame.find('select').prop('disabled', true);
        this.frame.find('input').prop('disabled', true);
        return this;
    },
    validate: function(){
        var rs = true;
//        this.frame.find('.input-group').each(function(){
//            var epgId = $(this).find('select').val();
//            var times = $(this).find('input').val();
//            if((epgId.length < 1) && (times.length > 1)){
//                $(this).find('select').addClass('error').one('change', function(){
//                    $(this).removeClass('error');
//                });
//                rs = false;
//            }else if((epgId.length > 1) && (times.length < 1)){
//                $(this).find('input').addClass('error').one('change', function(){
//                    $(this).removeClass('error');
//                });
//                rs = false;
//            }
//        });
        return rs; 
    },
    onChange: function(){
        if(this.config.onChange){
            this.config.onChange(this);
        }
    },
    destroy: function(){
        this.frame.remove();
    }
};
//添加到库
App.Form.lib['client-goods-spec-specifications'] = Client.Goods.Form.Specifications;
//货柜管理-货柜列表
App.util.ns('Client.Goods');
App.pages.add((function(){
    var NS = Client.Goods;
    var page = new App.Page({
        name: 'client/goods/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-window-restore"></i>',
            content: '商品管理'
        }, {
            content: '商品列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/client/goods',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'is_experience', title: '可否体验', width: '90px', items: [
                    [0, '可体验'],
                    [1, '不可体验']
                ]},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [0, '下线'],
                    [1, '在线']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:client.goods.create'},
                {parent: 'view', permission: 'op:client.goods.detail'},
                {parent: 'edit', permission: 'op:client.goods.update'},
                {parent: 'drop', permission: 'op:client.goods.delete'},
                {
                    type: 'inline', permission: 'op:client.goods.online',
                    name: '上线', operation: {type: 'change', url: 'online'},
                    conditions: [['status', '0']]
                },
                {
                    type: 'inline', permission: 'op:client.goods.offline',
                    name: '下线', operation: {type: 'change', url: 'offline'},
                    conditions: [['status', '1']]
                },
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:client.goods.multiOnline', name: '上线', operation: {type: 'change', url: 'multiOnline', confirm: true}},
                    {type: 'multi', permission: 'op:client.goods.multiOffline', name: '下线', operation: {type: 'change', url: 'multiOffline', confirm: true}}
                ], permission:[
                    'op:client.goods.multiOnline',
                    'op:client.goods.multiOffline'
                ]},
                {parent: 'multiDrop', permission: 'op:client.goods.multiDelete'},
                {parent: 'oplog', permission: 'op:client.goods.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//货柜与商品-报修申请
App.util.ns('Client.Apply.Repair');
App.pages.add((function(){
    var NS = Client.Apply.Repair;
    var page = new App.Page({
        name: 'client/apply/repair/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-window-restore"></i>',
            content: '货柜管理'
        }, {
            content: '报修申请'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/client/apply/repair',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: [
                    {name: '货柜', width: '120px', value: function(item){
                        return item.cabinet ? item.cabinet.name : '-- --';
                    }},
                    {name: '格子', width: '150px', value: function(item){
                        if(item.cell){
                            return '第 '+item.cell.row + ' 行，第' + item.cell.col + ' 列';
                        }
                        return '-- --';
                    }},
                    {name: '商品', width: '200px', value: function(item){
                        return item.cell && item.cell.goods ? item.cell.goods.name : '-- --';
                    }},
                    {name: '类型', width: '100px',value: function(item){
                        switch (item.type+'') {
                            case '1':
                                return '柜子问题';
                            case '2':
                                return '仪器问题';
                        }
                    }},
                    {name: '状态', width: '90px',value: function(item){
                        switch (item.status+'') {
                            case '0':
                                return '未处理';
                            case '1':
                                return '已处理';
                        }
                    }},
                    {name: '申请日期', width: '80px', value: function(item){
                        return App.util.formator.date(item.created_at);
                    }}
                ]
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [0, '未处理'],
                    [1, '已处理']
                ]}
            ],
            menu: [
                {parent: 'view', permission: 'op:client.apply.repair.detail'},
                {type: 'inline', permission: 'op:client.apply.repair..finish', name: '处理完成', operation: {type: 'change', url: 'finish'}, conditions: [['status', '0']]},
                {parent: 'drop', permission: 'op:client.apply.repair..delete'},
                {type: 'multi', name: '状态', openable: true, permission: 'op:client.apply.repair..multiFinish', 
                    items: [
                        {
                            type: 'multi', permission: 'op:client.apply.repair..multiOnline', name: '处理完成', 
                            operation: {
                                type: 'change', url: 'multiFinish', confirm: true
                            }
                        }
                    ] 
                },
                {parent: 'multiDrop', permission: 'op:client.apply.repair..multiDelete'},
                {parent: 'oplog', permission: 'op:client.apply.repair..getOpLogs'}
            ],
            detail: {
                form: {
                    items: [
                        {type: 'hidden', name: 'id'},
                        {type: 'hidden', name: 'client_id'},
                        {type: 'hidden', name: 'cabinet_id'},
                        {type: 'hidden', name: 'cell_id'},
                        {type: 'static', name: 'cabinet_name', title: '货柜名称', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'static', name: 'cell_name', title: '格子位置', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'static', name: 'goods_name', title: '商品名称', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'radio', name: 'type', title: '报修类型', required: true, 
                            items: [
                                [1, '柜子问题'],
                                [2, '仪器问题']
                            ],
                            defaults: '2',
                            rule: {
                                type: 'in',
                                in: ['1', '2']
                            }
                        },
                        {type: 'textarea', name: 'introduction', title: '补充说明', maxLength: 2000, rule: {
                            type: 'str',
                            range: [0, 2000]
                        }}
                    ],
                    onChange: function(self, item){
                        var cabinetName = item.cabinet ? item.cabinet.name : '-- --';
                        var cellName = item.cell ? '第 '+item.cell.row + ' 行，第' + item.cell.col + ' 列' : '-- --';
                        var goodsName = item.cell && item.cell.goods ? item.cell.goods.name : '-- --';
                        self.formItems['cabinet_name'].change(cabinetName);
                        self.formItems['cell_name'].change(cellName);
                        self.formItems['goods_name'].change(goodsName);
                    }
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面显示
    page.showStack.add('dataTable', function(){
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//货柜管理-换货申请
App.util.ns('Client.Apply.Exchange');
Client.Apply.Exchange.ExchangeApply = function(dataTable){
    var win = new App.Win({
        name: 'exchange_apply',
        title: '换货申请',
        width: '720px'
    });
    //列表
    win.dataTable = new App.DataTable({
        baseUrl: '/client/cabinet/cell',
        dataUrl: 'lists',
        table: {
            id: 'id',
            main: 1,
            showId: false,
            withSelect: false,
            columns: [
                {name: '位置', width: '90px', value: function(item){
                    return item.row + ' 行，' + item.col + ' 列';  
                }},
                {name: '原商品', value: function(item){
                    var name = item.goods ? item.goods.name : '未分配';
                    return $('<span style="margin: 0 6px">'+name+'</span>');
                }},
                {name: '期望商品', width: '350px', value: function(item){
                    var selector = new App.Form.SelectLists({
                        type: 'selectLists', 
                        name: 'id', 
                        title: '期望商品', 
                        data_id: 'goods_id', 
                        width: '600px',
                        data_name: function(item){
                            return item.id+': '+item.name;
                        },
                        dataTable: {
                            baseUrl: '/client/apply/exchange/goods',
                            dataUrl: 'lists',
                            data_id: 'id',
                            data_name: 'name',
                            table: {
                                id: 'id',
                                main: 0,
                                columns: [
                                    {name: '商品名', value: 'name'}
                                ]
                            },
                            filter: [
                                {type: 'keywords'}
                            ]
                        },
                        detail: {
                            form: {
                                items: App.util.copy(Admin.Goods.Goods.Conf.form)
                            }
                        }
                    });
                    selector.dataTable.win.fix(win.frame);
                    if(selector.detail){
                        selector.detail.win.fix(win.frame);
                    }
                    if(item.target){
                        selector.change(item.target.id, item.target.name, item.target);
                    }
                    selector.view();
                    return selector.frame;
                }}
            ]
        },
        after: function(self){
            self.frame.find('> .header').remove();
            self.frame.find('.data-table').addClass('table-bordered').removeClass('table-hover');
            self.fix(win.contentContainer);
        }
    });
    win.change = function(cabinet, info){
        win.setTitle('换货申请 - '+cabinet.name);
        var data = JSON.parse(info);
        win.dataTable.table.flushItmes(data);
        win.dataTable.frame.find('tbody td').css({padding: '0'});
        return win;
    };
    win.hide();
    return win;
};
//货柜管理-换货申请
App.util.ns('Client.Apply.Exchange');
App.pages.add((function(){
    var NS = Client.Apply.Exchange;
    var page = new App.Page({
        name: 'client/apply/exchange/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-window-restore"></i>',
            content: '货柜管理'
        }, {
            content: '换货申请'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/client/apply/exchange',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: [
                    {name: '货柜', width: '150px', value: function(item){
                        return item.cabinet ? item.cabinet.name : '-- --';
                    }},
                    {name: '状态', width: '90px',value: function(item){
                        switch (item.status+'') {
                            case '0':
                                return '未处理';
                            case '1':
                                return '已处理';
                        }
                    }},
                    {name: '申请日期', width: '80px', value: function(item){
                        return App.util.formator.date(item.created_at);
                    }}
                ]
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [0, '未处理'],
                    [1, '已处理']
                ]}
            ],
            menu: [
                {
                    type: 'inline',
                    name: '查看',
                    icon: '<i class="fa fa-eye"></i>',
                    floatable: true,
                    permission: 'op:client.apply.exchange.detail',
                    operation: function(dataTable, item){
                        var win = dataTable.wins.get('exchangeApply').show();
                        win.change(item.cabinet, item.goods_info).show();
                    }
                },
                {type: 'inline', permission: 'op:client.apply.exchange.finish', name: '处理完成', operation: {type: 'change', url: 'finish'}, conditions: [['status', '0']]},
                {parent: 'drop', permission: 'op:client.apply.exchange.delete'},
                {type: 'multi', name: '状态', openable: true, permission: 'op:client.apply.exchange.multiFinish', items: [{
                        type: 'multi', permission: 'op:client.apply.exchange.multiOnline', name: '处理完成', operation: {
                        type: 'change', url: 'multiFinish', confirm: true
                    }}] 
                },
                {parent: 'multiDrop', permission: 'op:client.apply.exchange.multiDelete'},
                {parent: 'oplog', permission: 'op:client.apply.exchange.getOpLogs'}
            ],
            after: function(dataTable){
                dataTable.wins.add(new NS.ExchangeApply(dataTable), 'exchangeApply');
            }
        });
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面显示
    page.showStack.add('dataTable', function(){
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//员工管理
App.util.ns('Client.Staff');
Client.Staff.Conf = {
    columns: [
        {name: '姓名', value: 'nickname'},
        {name: '手机号', width: '120px',value: 'phone'},
//        {name: '性别', width: '80px',value: function(item){
//            switch (item.gender+'') {
//                case '0':
//                    return '未知';
//                case '1':
//                    return '男';
//                case '2':
//                    return '女';
//            }
//        }},
        {name: '状态', width: '80px',value: function(item){
            switch (item.client_bind_status+'') {
                case '0':
                    return '未绑定';
                case '1':
                    return '待审核';
                case '2':
                    return '审核通过';
                case '3':
                    return '审核未通过';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'nickname', title: '姓名', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'input', name: 'phone', title: '手机号', required: true, rule: {type: 'phone'}},
        {type: 'radio', name: 'gender', title: '性别', 
            items: [
                ['0', '未知'],
                ['1', '男'],
                ['2', '女']
            ], 
            defaults: '0'
        },
        {type: 'img', name: 'icon', title: '头像',rule: {
            type: 'str',
            range: [0, 255]
        }},
        {type: 'textarea', name: 'introduction', title: '简介', maxLength: 2000, rule: {
            type: 'str',
            range: [0, 2000]
        }}
    ]
};
//用户管理-用户列表
App.util.ns('Client.Staff');
App.pages.add((function(){
    var NS = Client.Staff;
    var page = new App.Page({
        name: 'client/staff/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-user"></i>',
            content: '员工管理'
        }, {
            content: '员工列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/client/staff',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'select', name: 'client_bind_status', title: '绑定状态', width: '120px', items: [
                    [1, '待审核'],
                    [2, '绑定完成'],
                    [3, '绑定未完成']
                ]},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'add', permission: 'op:client.staff.staff.create'},
                {parent: 'view', permission: 'op:client.staff.staff.detail'},
                {parent: 'edit', permission: 'op:client.staff.staff.update'},
                {type: 'inline', permission: 'op:client.staff.staff.passApply', name: '通过', 
                    operation: {type: 'change', url: 'passApply'}, 
                    conditions: [['client_bind_status', '1']]
                },
                {type: 'inline', permission: 'op:client.staff.staff.rejectApply', name: '驳回', 
                    operation: {type: 'change', url: 'rejectApply'}, 
                    conditions: [['client_bind_status', '1']]
                },
                {type: 'inline', permission: 'op:client.staff.staff.close', name: '解除绑定', 
                    operation: {type: 'change', url: 'close'}, 
                    conditions: [['client_bind_status', '2']]
                },
//                {parent: 'drop', permission: 'op:client.staff.staff.delete'},
                {type: 'multi', name: '绑定状态', openable: true, 
                    items: [
                        {type: 'multi', permission: 'op:client.staff.staff.multiPassApply', name: '审核通过', 
                            operation: {type: 'change', url: 'multiPassApply', confirm: true}
                        },
                        {type: 'multi', permission: 'op:client.staff.staff.multiRejectApply', name: '审核驳回', 
                            operation: {type: 'change', url: 'multiRejectApply', confirm: true}
                        },
                        {type: 'multi', permission: 'op:client.staff.staff.multiClose', name: '解除绑定', 
                            operation: {type: 'change', url: 'multiClose', confirm: true}
                        }
                    ], 
                    permission:[
                        'op:client.staff.staff.multiPassApply',
                        'op:client.staff.staff.multiRejectApply',
                        'op:client.staff.staff.multiOpen',
                        'op:client.staff.staff.multiClose'
                    ]
                },
//                {parent: 'multiDrop', permission: 'op:client.staff.staff.multiDelete'},
                {parent: 'oplog', permission: 'op:client.staff.staff.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//数据统计-订单列表-配置文件
App.util.ns('Client.Orders');
Client.Orders.Conf = {
    columns: [
        {name: '商品名称', value: 'name', value: function(item){
            return item.goods ? item.goods.name : '-- --';  
        }},
        {name: '使用员工', width: '180px', value: function(item){
            return item.user ? item.user.nickname+'（'+item.user.phone+'）' : '-- --';  
        }},
        {name: '柜子', width: '150px', value: function(item){
            return item.cabinet ? item.cabinet.name : '-- --';  
        }},
        {name: '位置', width: '100px', value: function(item){
            return item.cell ? item.cell.row + ' 行，' + item.cell.col + ' 列' : '-- --';  
        }},
        {name: '起止时间', width: '110px', value: function(item){
            var startTime = item.start_time ? App.util.formator.dateTime(item.start_time).substr(11, 5) : '--:--';
            var endTime = item.end_time ? App.util.formator.dateTime(item.end_time).substr(11, 5) : '--:--';
            return startTime+' ~ '+endTime;
        }},
        {name: '使用时长', width: '75px', value: function(item){
            var time = 0;
            var isNum = function (val){
                // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除
                if(val === "" || val === null){
                    return false;
                }
                if(!isNaN(val)){
                    return true;
                }else{
                    return false;
                }
            };  
            if(item.status+'' === '1' && isNum(item.end_time) && isNum(item.start_time) && parseInt(item.end_time) > parseInt(item.start_time)){
                time = parseInt(item.end_time) - parseInt(item.start_time);
            }
            return time ? Math.ceil(time / 60) +'分' : '-- --';
        }},
        {name: '订单金额', width: '100px', value: 'amount'},
        {name: '订单状态', width: '80px', value: function(item){
            switch (item.status+'') {
                case '0':
                    return '支付失败';
                case '1':
                    return '支付成功';
                case '2':
                    return '待支付';
            }
        }},
        {name: '订单时间', width: '90px', value: function(item){
            return App.util.formator.dateTime(item.created_at).substr(5, 11);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '商品名', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }}
    ]
};
//财务管理--订单列表
App.util.ns('Client.Orders');
App.pages.add((function(){
    var NS = Client.Orders;
    var page = new App.Page({
        name: 'client/orders/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-bar-chart-o"></i>',
            content: '数据统计'
        }, {
            content: '使用记录'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/client/orders',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'view', permission: 'op:admin.orders.orders.detail'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
//财务管理--订单列表
App.util.ns('Client.Stats');
App.pages.add((function(){
    var NS = Client.Stats;
    var page = new App.Page({
        name: 'client/stats/index'
    });
    page.jobs = [];
    page.flushData = function(month){
        App.util.request.getData({
            url: '/client/stats/index',
            data: {
                month: month
            },
            loading: new App.Loading({container: page.contentContainer}),
            success: function(data){
                for(var i in page.jobs){
                    page.jobs[i](data);
                }
            }
        });
    };
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-bar-chart-o"></i>',
            content: '数据统计'
        }, {
            content: '统计报表'
        }]);
        this.setContent($(`
            <style>
                .filter-container{
                    width: 100%;
                    height: 34px;
                    margin-top: 15px;
                }
                .date-name{
                    width: 120px;
                    height: 34px;
                    display: inline-block;
                    float: left;
                    line-height: 34px;
                }
                .date-selector{
                    width: 220px;
                    height: 34px;
                    display: inline-block;
                    margin-left: 10px;
                    float: left;
                }
                .title-container{
                    border-bottom: 1px solid #ededed;
                    position: relative;
                    padding: 10px 0;
                    margin: 15px 0 0 0;
                }
                .title-flag{
                    border-left: 5px solid #f26f20;
                    margin-right: 10px;
                }
                .title-explain{
                    color: #999;
                    font-size: 12px;
                    position: absolute;
                    right: 0;
                    top: 10px;
                }
                .stats-block{
                    width: 100%;
                    height: 150px;
                }
                .stats-block-top{
                    width: 100%;
                    height: 96px;
                    border: 1px solid #ccc;
                    text-align: center;
                }
                .stats-block-bottom{
                    width: 100%;
                    height: 54px;
                }
                .stats-block-left{
                    width: 50%;
                    height: 100%;
                    float: left;
                    border-left: 1px solid #ccc;
                    border-bottom: 1px solid #ccc;
                    text-align: center;
                    padding-top: 6px;
                }
                .stats-block-right{
                    width: 50%;
                    height: 100%;
                    float: left;
                    border-left: 1px solid #ccc;
                    border-right: 1px solid #ccc;
                    border-bottom: 1px solid #ccc;
                    text-align: center;
                    padding-top: 6px;
                }
                .stats-block-value{
                    color: #454545;
                    font-size: 34px;
                }
                .stats-block-text{
                    color: #999;
                    font-size: 14px;
                }
                .stats-block-value-sm{
                    color: #454545;
                    font-size: 14px;
                }
                .stats-block-text-sm{
                    color: #999;
                    font-size: 12px;
                }
            </style>
            <div style="padding: 0 15px;">
                <div class="filter-container">
                    <div class="date-name">
                        <span class="title-flag"></span>
                        <span>选择要统计的月份</span> 
                    </div>
                    <div class="date-selector"></div>
                </div>
                <div class="title-container">
                    <span class="title-flag"></span> 
                    <span><span class="month-name"></span>借用数据概览</span> 
                    <div class="title-explain">"--" 代表数据更新中</div>
                </div>
                <div class="row" style="margin-top: 10px;">
                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="stats-block">
                            <div class="stats-block-top">
                                <span class="stats-block-value data-user-total">--</span>
                                <div class="stats-block-text">
                                    <span>总使用人数</span>
                                </div>
                            </div>
                            <div class="stats-block-bottom">
                                <div class="stats-block-left">
                                    <span class="stats-block-value-sm data-user-incr-month">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较上个月</span>
                                    </div>
                                </div>
                                <div class="stats-block-right">
                                    <span class="stats-block-value-sm data-user-incr-avg">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较平均值</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="stats-block">
                            <div class="stats-block-top">
                                <span class="stats-block-value data-times-total">--</span>
                                <div class="stats-block-text">
                                    <span>总使用次数（次）</span>
                                </div>
                            </div>
                            <div class="stats-block-bottom">
                                <div class="stats-block-left">
                                    <span class="stats-block-value-sm data-times-incr-month">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较上个月</span>
                                    </div>
                                </div>
                                <div class="stats-block-right">
                                    <span class="stats-block-value-sm data-times-incr-avg">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较平均值</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="stats-block">
                            <div class="stats-block-top">
                                <span class="stats-block-value data-time-total">--</span>
                                <div class="stats-block-text">
                                    <span>总使用时长（小时）</span>
                                </div>
                            </div>
                            <div class="stats-block-bottom">
                                <div class="stats-block-left">
                                    <span class="stats-block-value-sm data-time-incr-month">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较上个月</span>
                                    </div>
                                </div>
                                <div class="stats-block-right">
                                    <span class="stats-block-value-sm data-time-incr-avg">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较平均值</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="stats-block">
                            <div class="stats-block-top">
                                <span class="stats-block-value data-amount-total">--</span>
                                <div class="stats-block-text">
                                    <span>总费用（元）</span>
                                </div>
                            </div>
                            <div class="stats-block-bottom">
                                <div class="stats-block-left">
                                    <span class="stats-block-value-sm data-amount-incr-month">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较上个月</span>
                                    </div>
                                </div>
                                <div class="stats-block-right">
                                    <span class="stats-block-value-sm data-amount-incr-avg">-- --</span>
                                    <div class="stats-block-text-sm">
                                        <span>较平均值</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="title-container">
                    <span class="title-flag"></span> 
                    <span><span class="month-name"></span>各仪器使用对比分析</span> 
                    <div class="title-explain"></div>
                </div>
                <div class="row" style="margin-top: 10px;">
                    <div class="col-sm-12">
                        <div class="panel panel-default" style="border-radius: 0;">
                            <div class="panel-body">
                                <div class="goods-month-times-percent" style="height: 320px;">
                                </div>
                            </div>
                            <div class="panel-footer text-center" style="background-color: #fff;border-radius: 0;">
                                <span class="month-name"></span>仪器使用次数占比
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row" style="margin-top: 10px;">
                    <div class="col-sm-12">
                        <div class="panel panel-default" style="border-radius: 0;">
                            <div class="panel-body">
                                <div class="goods-month-time-percent" style="height: 320px;">
                                </div>
                            </div>
                            <div class="panel-footer text-center" style="background-color: #fff;border-radius: 0;">
                                <span class="month-name"></span>仪器使用时长占比
                            </div>
                        </div>
                    </div>
                </div>
                <div class="title-container">
                    <span class="title-flag"></span> 
                    <span><span class="month-name"></span>各仪器使用趋势分析</span> 
                    <div class="title-explain"></div>
                </div>
                <div class="row" style="margin-top: 10px;">
                    <div class="col-sm-12">
                        <div class="panel panel-default" style="border-radius: 0;">
                            <div class="panel-body">
                                <div class="goods-month-times-trend" style="height: 410px;">
                                </div>
                            </div>
                            <div class="panel-footer text-center" style="background-color: #fff;border-radius: 0;">
                                <span class="month-name"></span>仪器使用次数趋势
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row" style="margin-top: 10px;">
                    <div class="col-sm-12">
                        <div class="panel panel-default" style="border-radius: 0;">
                            <div class="panel-body">
                                <div class="goods-month-time-trend" style="height: 410px;">
                                </div>
                            </div>
                            <div class="panel-footer text-center" style="background-color: #fff;border-radius: 0;">
                                <span class="month-name"></span>仪器使用时长趋势
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        `));
        var date = new App.Form.DateMonth({
            name: 'month',
            onChange: function (self){
                var month = App.util.formator.date(self.value()).substring(0, 7);
                page.flushData(month);
            }
        });
        page.frame.find('.filter-container .date-selector').append(date.frame);
        page.jobs.push(function(data){
            page.frame.find('.month-name').text(data.monthName);
            var global = data.global;
            //总使用用户
            page.frame.find('.data-user-total').text(global.user.total);//用户总数
            page.frame.find('.data-user-incr-month').text(global.user.incrMonth);//较上个月增长
            page.frame.find('.data-user-incr-avg').text(global.user.incrAvg);//较平均值增长
            //使用次数
            page.frame.find('.data-times-total').text(global.times.total);//总使用次数
            page.frame.find('.data-times-incr-month').text(global.times.incrMonth);//较上个月增长
            page.frame.find('.data-times-incr-avg').text(global.times.incrAvg);//较平均值增长
            //总使用时长
            var totalTime = global.time.total ? parseFloat(parseInt(global.time.total)/3600).toFixed(2) : 0;
            page.frame.find('.data-time-total').text(totalTime);//总使用时长
            page.frame.find('.data-time-incr-month').text(global.time.incrMonth);//较上个月增长
            page.frame.find('.data-time-incr-avg').text(global.time.incrAvg);//较平均值增长
            //总产生费用
            page.frame.find('.data-amount-total').text(parseFloat(global.amount.total).toFixed(2));//总费用
            page.frame.find('.data-amount-incr-month').text(global.amount.incrMonth);//较上个月增长
            page.frame.find('.data-amount-incr-avg').text(global.amount.incrAvg);//较平均值增长
            //各仪器使用情况对比
            var timesData = data.group.times;
            var timeData = data.group.time;
            var timesItems = [];
            var timeItems = [];
            for(var i in timesData){
                timesItems.push(timesData[i].name);
            }
            for(var i in timeData){
                timeItems.push(timeData[i].name);
            }
            echarts.init(page.frame.find('.goods-month-times-percent').first()[0]).setOption({
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    x: 'left',
                    data: timesItems
                },
                series: [
                    {
                        name:'访问来源',
                        type:'pie',
                        radius: ['40%', '55%'],
                        data: timesData
                    }
                ]
            });
            echarts.init(page.frame.find('.goods-month-time-percent').first()[0]).setOption({
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    x: 'left',
                    data: timeItems
                },
                series: [
                    {
                        name:'访问来源',
                        type:'pie',
                        radius: ['40%', '55%'],
                        data: timeData
                    }
                ]
            });
            //各仪器使用使用趋势
            var goodsTimesData = data.goods.times;
            var goodsTimeData = data.goods.time;
            echarts.init(page.frame.find('.goods-month-times-trend').first()[0]).setOption({
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    x: 'left',
                    top: '20px',
                    data: goodsTimesData.goods
                },
                grid: {
                    top: '20px',
                    left: '220px',
                    right: '20px',
                    bottom: '10px',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: goodsTimesData.days
                },
                yAxis: {
                    type: 'value'
                },
                series: goodsTimesData.data
            });
            echarts.init(page.frame.find('.goods-month-time-trend').first()[0]).setOption({
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    x: 'left',
                    top: '20px',
                    data: goodsTimeData.goods
                },
                grid: {
                    top: '20px',
                    left: '220px',
                    right: '20px',
                    bottom: '10px',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: goodsTimeData.days
                },
                yAxis: {
                    type: 'value'
                },
                series: goodsTimeData.data
            });
        });
        page.flushData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
    });
    return page;
})());
//货柜与商品-商品列表-配置文件
App.util.ns('Client.Feedback');
Client.Feedback.Conf = {
    columns: [
        {name: '反馈标题', value: 'client_id'},
        {name: '反馈类型', width: '120px', value: function(item){
            switch (item.type+'') {
                case '1':
                    return '意见反馈';
                case '1':
                    return '已处理';
            }
        }},
        {name: '处理状态', width: '80px', value: function(item){
            switch (item.status+'') {
                case '0':
                    return '未处理';
                case '1':
                    return '已处理';
            }
        }},
        {name: '创建日期', width: '80px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'radio', name: 'type', title: '类型', required: true, items:[
            ['1', '提意见'],
            ['2', '申请中医']
        ], defaults: '1'},
        {type: 'input', name: 'title', title: '标题', required: true, maxLength: 80, rule: {
            type: 'str',
            range: [1, 160]
        }},
        {type: 'textarea', name: 'content', title: '详细说明', maxLength: 2000, rule: {
            type: 'str',
            range: [0, 2000]
        }}
    ]
};
//货柜与商品-商品列表
App.util.ns('Client.Feedback');
App.pages.add((function(){
    var NS = Client.Feedback;
    var page = new App.Page({
        name: 'client/feedback/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-question-circle-o"></i>',
            content: '意见反馈'
        }, {
            content: '反馈列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/client/feedback',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '类型', width: '120px', items: [
                    [1, '提意见'],
                    [2, '申请中医']
                ]},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [0, '未处理'],
                    [1, '已处理']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:client.feedback.feedback.create'},
                {parent: 'view', permission: 'op:client.feedback.feedback.detail'},
                {parent: 'edit', permission: 'op:client.feedback.feedback.update'},
                {type: 'inline', permission: 'op:client.feedback.feedback.finish', name: '处理完成', operation: {type: 'change', url: 'finish'}, conditions: [['status', '0']]},
                {parent: 'drop', permission: 'op:client.feedback.delete'},
                {type: 'multi', name: '状态', openable: true, permission: 'op:client.feedback.feedback.multiFinish', items: [{
                        type: 'multi', permission: 'op:clientfeedback.feedback.multiOnline', name: '处理完成', operation: {
                        type: 'change', url: 'multiFinish', confirm: true
                    }}]
                },
                {parent: 'multiDrop', permission: 'op:client.feedback.feedback.multiDelete'},
                {parent: 'oplog', permission: 'op:client.feedback.feedback.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());
